This is the notebook associated with the publication “TITLE”. The code required to replicate the results can be found below. An additional accompanying file is also made avaiable in the same github directory containing the various functions used in this study. In a nutshell, participants unerwent 2 weeks of EMA, coupled with EPA (physiological arousal measures acquired via a wearable). One week has a high stakes exam, while the other is a control week. We look at the differences between the weeks, and then try to see momentary associations, followed by the ability of ML Models to classify the week types. Data can be made avaialbe upon request. Before we begin though, we load in all the libraries used. All libraries used must first be loaded. It may be that some libraries are not used, and that is due to edits and rewrites, but we keep them loaded just in case.
In addition to loading librarires, we also make a preset theme for the graphs to plot editing a bit easier. For that reason, we specify themes here. Additionally, we specify the number of cores we need, as this is important in perfroming some parallel analysis.
# Theme 1
ggtheme <- theme (text=element_text(size=16, family="Cambria"),
legend.position = "none",
axis.text.y = element_blank(),axis.text.x = element_text(size=16),
axis.ticks.y = element_blank(),
plot.title = element_text(size=16, hjust=0.5),
panel.background = element_rect(fill="transparent"),
panel.grid.minor.y = element_line(size=3),
panel.grid.major = element_line(colour = "aliceblue") )
# Theme 2
ptheme <- theme(text=element_text(size=11, family="Calibri"),
axis.line = element_line(size = 1, colour = "grey"),
panel.background = element_rect(fill="transparent"),
plot.background = element_rect(fill = "transparent", color = NA), # bg of the plot
panel.grid.minor.y = element_line(colour="grey95"),
panel.grid.major.y = element_line(colour = "grey95"))
# Set number of cores
NoCores <- as.numeric(availableCores())-1
Some custom functions were used as part of this study, and must be loaded. These functions are also provided in this github directory.
source("functions.R")
Now that all the set-up has been complete, we can start with loading the data. Due to privacy issues, only a specific file (and not the full file) with anonymized categorical variables for the program are provided in this code. This contains the same data used in the analysis, but with recoding of factors to mask potential identifiers. This has also been cleaned to generate a few different variables required for analysis using functions in the “function.R” file. These variables are given a specific suffix as described below:
#read.csv("data/EMA_Clean_Anon.csv")
print(EMA_Pub)
Warning messages:
1: Unknown or uninitialised column: `completed`.
2: Unknown or uninitialised column: `completed`.
3: Unknown or uninitialised column: `completed`.
4: Unknown or uninitialised column: `completed`.
5: Unknown or uninitialised column: `completed`.
6: Unknown or uninitialised column: `completed`.
7: Unknown or uninitialised column: `completed`.
8: Unknown or uninitialised column: `completed`.
9: Unknown or uninitialised column: `completed`.
For some basic analysis, we also get the mean of the subjective stress measures. These are used for visualization.
##Average stress Measure
EMA_Data$mean_stress <- rowSums(EMA_Data[c('event_tot_z', 'activity_tot_z', 'social_tot_z')], na.rm=TRUE)
EMA_Data$mean_stress_c <- rowSums(EMA_Data[c('event_tot_c', 'activity_tot_c', 'social_tot_c')], na.rm=TRUE)
EMA_Data$mean_stress_s <- scales::rescale(EMA_Data$mean_stress_c, to=c(1, 10))
EMA_Data$mean_stress_l <- lag_var(x="mean_stress_c", id="Sub_nr_week", obs="obs", day= "ema_day_num", data=EMA_Data, lag=1)
##Make Part into a factor variable for early and late
EMA_Data$week_type <- EMA_Data$week_type-1
EMA_Data$Week_Type <- factor(EMA_Data$week_type, levels=c('0','1'),
labels=c('Control','Stress'))
Before running any stats, we should take a look at some descriptive stats to get an overall feel of our data.
Lets first check compliance rates to see how well our subjects adhered to the sampling. We first check the compliance rates uncorrected for the time at which they were acquired, followed by correction of the time limits. We set this to 1 hour since we only have 6 surveys, and our subjects had varying time schedules. It is indeed a limitation, but we had to do this for methodological reasons.
Compliance rates uncorrected for time off-sets
# Recod compliance variable
EMA_Data$completed[EMA_Data$survey_progress==100] <- 1
Unknown or uninitialised column: `completed`.
# Per subject
calc.nomiss(completed, castor_record_id, data=EMA_Data, prop=T)
sub_001 sub_002 sub_003 sub_004 sub_005 sub_006 sub_007 sub_008 sub_009 sub_010 sub_011 sub_012 sub_013 sub_014 sub_015
0.9759036 0.8902439 0.9259259 0.8148148 0.9259259 1.0000000 0.9518072 0.9135802 0.9880952 0.6125000 1.0000000 0.9756098 0.9880952 0.9756098 0.6835443
sub_016 sub_017 sub_018 sub_019 sub_020 sub_021 sub_022 sub_023 sub_024 sub_025 sub_026 sub_027 sub_028 sub_029 sub_030
1.0000000 0.8421053 0.7307692 0.9759036 0.9113924 0.8734177 0.9113924 0.9759036 0.9879518 0.9487179 0.9878049 0.9500000 0.9753086 0.9240506 0.9480519
sub_031 sub_032 sub_033 sub_034 sub_035 sub_036 sub_037 sub_038 sub_039 sub_040 sub_043 sub_044 sub_045 sub_046 sub_047
0.8271605 0.7887324 0.9210526 0.9240506 0.9382716 0.9375000 0.9743590 0.6562500 0.9878049 0.9506173 0.9638554 0.9518072 0.9166667 0.9634146 0.9382716
sub_048 sub_050 sub_052 sub_053 sub_054 sub_057 sub_058 sub_059 sub_060 sub_061 sub_062 sub_063 sub_064 sub_065 sub_066
0.8795181 0.9350649 0.9500000 0.8974359 0.9390244 0.9375000 0.9506173 0.9629630 0.9500000 1.0000000 1.0000000 0.8947368 0.9634146 0.9880952 0.9759036
sub_067 sub_068 sub_069 sub_070 sub_071 sub_072 sub_073 sub_074 sub_075 sub_076 sub_077 sub_078 sub_081 sub_082 sub_083
1.0000000 0.9761905 0.8028169 0.9367089 0.9625000 0.9125000 0.9350649 NA 0.9761905 0.9879518 0.9518072 1.0000000 0.9880952 0.8780488 0.8170732
sub_084 sub_085 sub_086 sub_087 sub_088 sub_089 sub_105 sub_115 sub_141 sub_142 sub_149 sub_151 sub_153 sub_155 sub_156
0.8571429 NA NA NA NA NA 0.7230769 1.0000000 0.9880952 0.9629630 0.9200000 1.0000000 NA 0.8400000 0.9200000
sub_161
NA
# more summary statistics for compliance
summary(calc.nomiss(completed, castor_record_id, data=EMA_Data, prop=TRUE))
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
0.6125 0.9119 0.9500 0.9249 0.9759 1.0000 8
Without correcting for time offsets, our EMA measures seem to be nice. Lets see if I correct for timing if it makes a difference next what will happen. We will give participant one hour to finish the survey. If they dont finish it in that time window, we will count it as missing.
Compliance rates correcting for time of completion. first drop any survey that is not complete more than 80%. I then create a variabe that tells as when the survey was completed in terms of time (not date). I then conditionally set the completion variable to zero if the survey does not fall within the completed time window given the beep.
# Set up some stuff for replace and refill
EMA_Data$survey_completed_on <- as.character(EMA_Data$survey_completed_on)
EMA_Data$survey_completed_time <- as.ITime(EMA_Data$survey_completed_on)
EMA_Data$completed[EMA_Data$survey_progress < 80] <- 0
# Replace and refill conditionals for completion, factoring times
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("10:30:00")) & EMA_Data$ema_beep==1] <- 0
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("13:00:00")) & EMA_Data$ema_beep==2] <- 0
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("15:30:00")) & EMA_Data$ema_beep==3] <- 0
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("18:00:00")) & EMA_Data$ema_beep==4] <- 0
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("20:30:00")) & EMA_Data$ema_beep==5] <- 0
EMA_Data$completed[EMA_Data$survey_completed_time >= (as.ITime("23:00:00")) & EMA_Data$ema_beep==6] <- 0
# Reformat 0 to Nan, and get new completion rates
EMA_Data$completed[EMA_Data$completed == 0] <- NA
calc.nomiss(completed, castor_record_id, data=EMA_Data,prop=TRUE)
sub_001 sub_002 sub_003 sub_004 sub_005 sub_006 sub_007 sub_008 sub_009 sub_010 sub_011 sub_012 sub_013 sub_014 sub_015
0.9638554 0.7073171 0.7160494 0.6913580 0.9259259 0.9761905 0.9277108 0.8395062 0.9404762 0.5625000 0.8641975 0.9512195 0.9404762 0.7682927 0.4050633
sub_016 sub_017 sub_018 sub_019 sub_020 sub_021 sub_022 sub_023 sub_024 sub_025 sub_026 sub_027 sub_028 sub_029 sub_030
0.9404762 0.8421053 0.7051282 0.9277108 0.8734177 0.7721519 0.8101266 0.9638554 0.9879518 0.9487179 0.9756098 0.9375000 0.9506173 0.9240506 0.9480519
sub_031 sub_032 sub_033 sub_034 sub_035 sub_036 sub_037 sub_038 sub_039 sub_040 sub_043 sub_044 sub_045 sub_046 sub_047
0.8271605 0.7887324 0.8815789 0.8354430 0.9259259 0.9250000 0.9615385 0.4687500 0.8658537 0.9382716 0.9518072 0.9397590 0.7976190 0.9390244 0.9382716
sub_048 sub_050 sub_052 sub_053 sub_054 sub_057 sub_058 sub_059 sub_060 sub_061 sub_062 sub_063 sub_064 sub_065 sub_066
0.8795181 0.8961039 0.9500000 0.8717949 0.9268293 0.9375000 0.9506173 0.9259259 0.9375000 0.9523810 1.0000000 0.8815789 0.9146341 0.9166667 0.9397590
sub_067 sub_068 sub_069 sub_070 sub_071 sub_072 sub_073 sub_074 sub_075 sub_076 sub_077 sub_078 sub_081 sub_082 sub_083
0.9285714 0.6428571 0.5492958 0.7721519 0.9125000 0.8500000 0.7922078 NA 0.9404762 0.8915663 0.9156627 0.8809524 0.9404762 0.8048780 0.7317073
sub_084 sub_085 sub_086 sub_087 sub_088 sub_089 sub_105 sub_115 sub_141 sub_142 sub_149 sub_151 sub_153 sub_155 sub_156
0.8571429 NA NA NA NA NA 0.7076923 0.8780488 0.8452381 0.9629630 0.8400000 0.9642857 NA 0.6133333 0.9200000
sub_161
NA
summary(calc.nomiss(completed, castor_record_id, data=EMA_Data,prop=TRUE))
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
0.4051 0.8313 0.9157 0.8638 0.9405 1.0000 8
When we correct for the timing, we actually still have decent completion rates.
For the population descriptives, we use a different dataframe. So we oresent them below:
describe(EMA_descr$Sex)
EMA_descr$Sex
n missing distinct
83 0 2
Value Female Male
Frequency 51 32
Proportion 0.614 0.386
describe(factor(EMA_descr$Contraceptive_use))
factor(EMA_descr$Contraceptive_use)
n missing distinct
83 0 4
Value c Male No Yes
Frequency 8 32 19 24
Proportion 0.096 0.386 0.229 0.289
describe((EMA_descr$Program))
(EMA_descr$Program)
n missing distinct
83 0 2
Value BSc_BioMed BSc_Med
Frequency 22 61
Proportion 0.265 0.735
describe(EMA_descr$First_Week)
EMA_descr$First_Week
n missing distinct
83 0 2
Value Control-First Exam-First
Frequency 56 27
Proportion 0.675 0.325
# Number of days between weeks
summary(abs(EMA_descr$Column1))
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 14.00 15.00 15.96 16.00 33.00
psych::describe(EMA_Data$physical_disruption)
After getting the population descriptives, we should next derive some E4 Quality measures. A lot of the data which is poor quality is already removed early on in the preprocessing pipeline. Instead we can check how many recordings were captured for the IBI data, and the overall movement during testing.
This is a measure of the total duration of IBI’s detected in our windows.
ggplot(EMA_Data, aes(x=ibi_based_quality, colour=ibi_based_quality)) + geom_histogram()
count(EMA_Data$ibi_based_quality > 0.3)
mean(EMA_Data$ibi_based_quality, na.rm=T)
[1] 0.2728208
Next we will check if the IBI quality is related to the ACC data. This gives us a good idea of how much motion is affecting our data.
ggplot(EMA_Data, aes(x=ibi_based_quality, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + coord_cartesian(ylim = c(0,10), xlim=c(0, 2.5)) + ggtheme + theme(axis.ticks.y=element_line(size=1), axis.text.y = element_text(size=12)) + ylab("ACC Delta") + xlab ("IBI Based Quality")
ggplot(EMA_Data, aes(x=ibi_based_quality, y=hr_sd)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1), axis.text.y = element_text(size=12)) + ylab("HR SD") + xlab ("IBI Based Quality")
summary(lm(ibi_based_quality ~ hr_sd, data=EMA_Data))
Call:
lm(formula = ibi_based_quality ~ hr_sd, data = EMA_Data)
Residuals:
Min 1Q Median 3Q Max
-0.42489 -0.16350 -0.05393 0.11612 1.45938
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.473229 0.005947 79.58 <2e-16 ***
hr_sd -0.024096 0.000601 -40.09 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2211 on 4709 degrees of freedom
(1912 observations deleted due to missingness)
Multiple R-squared: 0.2545, Adjusted R-squared: 0.2543
F-statistic: 1607 on 1 and 4709 DF, p-value: < 2.2e-16
Next we will check if the SC signals are related to the ACC. Basically this is just doing explorartory analysis to double check certain things we already expect in our data.
fig.sc_tonic <- ggplot(EMA_Data, aes(x=sc_tonic_mean, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1), axis.text.y = element_text(size=12)) + ylab("ACC Delta") + xlab ("SC Tonic")
fig.sc_mag <- ggplot(EMA_Data, aes(x=sc_phasic_mag, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1)) + xlab ("SC Mag")
fig.sc_num <- ggplot(EMA_Data, aes(x=sc_phasic_num, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1)) + xlab ("SC Num")
fig.sc_auc <- ggplot(EMA_Data, aes(x=sc_phasic_auc, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1)) + xlab ("SC AUC")
fig.sc_dur <- ggplot(EMA_Data, aes(x=sc_phasic_dur, y=acc_delta)) + geom_smooth(method="lm", fullrange=F ) + ggtheme + theme(axis.ticks.y=element_line(size=1)) + xlab ("SC Dur")
fig.temp_mean <- ggplot(EMA_Data, aes(x=physical_excercise_dur, y=acc_delta, colour="red")) + geom_smooth(method="lm") + ggtheme
ggarrange(fig.sc_tonic, fig.sc_mag, fig.sc_num, fig.sc_auc, fig.sc_dur, fig.temp_mean)
`geom_smooth()` using formula 'y ~ x'
Removed 1752 rows containing non-finite values (stat_smooth).font family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font databasefont family 'Cambria' not found in PostScript font database`geom_smooth()` using formula 'y ~ x'
Removed 1752 rows containing non-finite values (stat_smooth).`geom_smooth()` using formula 'y ~ x'
Removed 1752 rows containing non-finite values (stat_smooth).`geom_smooth()` using formula 'y ~ x'
Removed 1752 rows containing non-finite values (stat_smooth).`geom_smooth()` using formula 'y ~ x'
Removed 1752 rows containing non-finite values (stat_smooth).`geom_smooth()` using formula 'y ~ x'
Removed 1513 rows containing non-finite values (stat_smooth).
I am curuious to see if there are trends in the EMA items too. Below I will plot the aggreagte data as a function of beep (EMA instance), separated by week.
vars.ema <- c("mood_positive_z", "mood_negative_z", "event_tot_z", "activity_tot_z", "social_tot_z", "physical_tot_z")
plot.ema_trend <- list()
for ( i in vars.ema) {
plot <- ggplot(EMA_Data, aes(y=get(i), x=ema_survey, colour=Week_Type)) + geom_line(stat="summary", aes(colour=Week_Type)) + geom_ribbon(aes(fill=Week_Type), stat="summary", alpha=0.3, colour=NA)+scale_x_continuous() + ylab(i)
plot.ema_trend[[i]] <- plot
}
ggarrange(plotlist=plot.ema_trend, common.legend = T)
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
Removed 477 rows containing non-finite values (stat_summary).No summary function supplied, defaulting to `mean_se()`
It looks like we have a bit of a trend in our data. The closer we are to the exams, the more stressed people become. We will need to add this to our models to correct for the trend statistically.
After plotting our variables over all the week, it will be interesting to check the aggregate stress changes, and how each subjects stress reactivity looks like. For this, I will make an average dataframe across the week, so we can look at the average change in mood.
#Average Stress per Week:
EMA_avg <- EMA_Data
# Now I can do some merging
EMA_avg <- aggregate(EMA_avg, by=list(EMA_avg$castor_record_id, EMA_avg$Week_Type), FUN=mean, na.rm=T, na.warn=F)
EMA_avg$castor_record_id <- EMA_avg$Group.1
EMA_avg$Week_Type <- EMA_avg$Group.2
EMA_avg$Week_Type <- factor(EMA_avg$Week_Type, levels=c('Control','Stress'),
labels=c('Control','Exam'))
# Split the averaged DF to control and stress week
EMA_avg_exam <- subset(EMA_avg, Week_Type=="Exam")
EMA_avg_control <- subset(EMA_avg, Week_Type!="Exam")
# Merge by week to calculate change
EMA_avg_wide <- merge(EMA_avg_exam, EMA_avg_control, by='castor_record_id', suffixes=c('_exam', '_control'))
# Make Aggregated variables
EMA_avg_wide$mood_positive <-((EMA_avg_wide$mood_positive_control + EMA_avg_wide$mood_positive_exam)/2)
EMA_avg_wide$mood_negative <-((EMA_avg_wide$mood_negative_control + EMA_avg_wide$mood_negative_exam)/2)
EMA_avg_wide$activity_tot <-((EMA_avg_wide$activity_tot_control + EMA_avg_wide$activity_tot_exam)/2)
EMA_avg_wide$social_tot <-((EMA_avg_wide$social_tot_control + EMA_avg_wide$social_tot_exam)/2)
EMA_avg_wide$event_tot <-((EMA_avg_wide$event_tot_control + EMA_avg_wide$event_tot_exam)/2)
EMA_avg_wide$physical_tot <-((EMA_avg_wide$physical_tot_control + EMA_avg_wide$physical_tot_exam)/2)
# Make stress change, and mean centrer it
EMA_avg_wide$stress_reactivity <- EMA_avg_wide$mean_stress_exam - EMA_avg_wide$mean_stress_control
EMA_avg_wide$stress_reactivity_c <- EMA_avg_wide$mean_stress_c_exam - EMA_avg_wide$mean_stress_c_control
EMA_avg_wide$stress_reactivity_z <- scale(EMA_avg_wide$stress_reactivity, center = TRUE, scale = TRUE)
#Box Plot
mean_box <- ggplot(EMA_avg, aes(y=mean_stress, x=Week_Type, colour=Week_Type,fill=Week_Type, na.rm = TRUE)) +
geom_boxplot(alpha=1/2) + geom_jitter(width=0.1, alpha=1/2)+
scale_y_continuous()+ scale_x_discrete()+
ggtitle("Stress Levels per Week")+
xlab("") + ylab("Aggregated stress measure\n")+ ggtheme
mean_box + coord_fixed(ratio=1.5)
scat_str <- ggplot (EMA_avg_wide, aes(y=stress_reactivity_c, x=factor(1), colour=stress_reactivity_c) ) +
geom_jitter( width = 0.25, alpha=0.75, size = 2) +
ggtitle("Individual Stress Reactivity to Exams\n")+ylab("Stress Reactivity\n")+labs(color = "Stress Reactivity\n")+
theme(text=element_text(size=18, family="Cambria"),
plot.title=element_text (size=20, hjust=0.5),
axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank(),
axis.text.y = element_text(size=18),axis.title.y=element_text(size=18),
panel.background = element_rect(fill="white"),
panel.grid.minor.y = element_line(size=3),
panel.grid.major = element_line(colour = "aliceblue"))
scat_str + scale_color_gradient(low="blue", high="red") + coord_fixed(ratio = 0.6)
Now we can do some statistical modeling with inferential stats. We use different glmer models for our data. The method used it simple: We fit the model multiple times with different families of models and different links. Based on the AIC, and the residuals, we pick the best fitting model. Additionally, we use a maximal fit approach. For our main fixed effect of interest, I also model a random slope and ranom intercept. For other covariates, I model them as fixed effects with random slopes and a fixed intercept. Subject is used as a random effect in all our models.
First we test our paradigm, and see whether it also has effects on our outcome measures of mood and physiological arousal. We check for main effects of week type (control or stress) on the variables. We also model covariates: Sex, Program, activity levels, and survey instance
Here we test the confirmatory analysis. We expect to see increased subjective stress in the stress week, which is confirmed in the models. For simplicity, we only present the final model selected based on the optimal fit.
# Model
glmer.physical_week<- glmer( physical_tot_s ~ Week_Type + #Model week
Sex + Program + # Model sex and program
First_Week + ema_day*ema_beep_f + # Model day related items
acc_delta + physical_excercise_dur + acc_delta*physical_excercise_dur + # Model movement
(1+Week_Type|castor_record_id) + (0+acc_delta|castor_record_id) +
(0+ema_survey|castor_record_id) + (0+physical_excercise_dur|castor_record_id) +
(1|castor_record_id:ema_day:ema_beep_f),
data=EMA_Data,
#family=Gamma,
control=lmerControl(calc.derivs = FALSE))
# Model Summary
summary(glmer.physical_week)
Linear mixed model fit by REML ['lmerMod']
Formula: physical_tot_s ~ Week_Type + Sex + Program + First_Week + ema_day * ema_beep_f + acc_delta + physical_excercise_dur + acc_delta *
physical_excercise_dur + (1 + Week_Type | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + ema_survey | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
REML criterion at convergence: 16810.1
Scaled residuals:
Min 1Q Median 3Q Max
-3.5099 -0.6493 -0.0581 0.5893 5.4381
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.0426767 0.20658
castor_record_id physical_excercise_dur 0.0363058 0.19054
castor_record_id.1 ema_survey 0.0007335 0.02708
castor_record_id.2 acc_delta 0.0000000 0.00000
castor_record_id.3 (Intercept) 0.8433427 0.91834
Week_TypeStress 0.6104499 0.78131 -0.34
Residual 1.3327886 1.15446
Number of obs: 5110, groups: castor_record_id:ema_day:ema_beep_f, 3069; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 4.5630564 0.2391308 19.082
Week_TypeStress -0.0620684 0.0931086 -0.667
SexMale -0.2994700 0.2088982 -1.434
ProgramBSc_Med -0.0605230 0.2293859 -0.264
First_WeekExam-First 0.2777947 0.2143295 1.296
ema_dayEMA 2. -0.1915930 0.1502740 -1.275
ema_dayEMA 3. 0.0342863 0.1567591 0.219
ema_dayEMA 4. -0.2060100 0.1628749 -1.265
ema_dayEMA 5. -0.4123216 0.1687553 -2.443
ema_dayEMA 6. -0.2288882 0.1791044 -1.278
ema_dayEMA 7. -0.4521119 0.1907229 -2.371
ema_beep_f2 -0.2055534 0.1487070 -1.382
ema_beep_f3 -0.2976639 0.1477558 -2.015
ema_beep_f4 -0.0009249 0.1487246 -0.006
ema_beep_f5 -0.8137608 0.1581781 -5.145
ema_beep_f6 -0.6040162 0.1527357 -3.955
acc_delta -0.0148329 0.0034458 -4.305
physical_excercise_dur 0.5563173 0.1682507 3.306
ema_dayEMA 2.:ema_beep_f2 0.0228770 0.2071262 0.110
ema_dayEMA 3.:ema_beep_f2 -0.0906231 0.2118184 -0.428
ema_dayEMA 4.:ema_beep_f2 -0.1270573 0.2141211 -0.593
ema_dayEMA 5.:ema_beep_f2 0.1538572 0.2112295 0.728
ema_dayEMA 6.:ema_beep_f2 -0.0631026 0.2120423 -0.298
ema_dayEMA 7.:ema_beep_f2 0.1628191 0.2181488 0.746
ema_dayEMA 2.:ema_beep_f3 0.1771502 0.2086052 0.849
ema_dayEMA 3.:ema_beep_f3 -0.2428685 0.2100991 -1.156
ema_dayEMA 4.:ema_beep_f3 -0.0354755 0.2125094 -0.167
ema_dayEMA 5.:ema_beep_f3 0.2196079 0.2103857 1.044
ema_dayEMA 6.:ema_beep_f3 -0.1684959 0.2119922 -0.795
ema_dayEMA 7.:ema_beep_f3 0.0989181 0.2147959 0.461
ema_dayEMA 2.:ema_beep_f4 0.0281753 0.2095475 0.134
ema_dayEMA 3.:ema_beep_f4 -0.2938972 0.2099347 -1.400
ema_dayEMA 4.:ema_beep_f4 -0.0870502 0.2119519 -0.411
ema_dayEMA 5.:ema_beep_f4 0.2754781 0.2121629 1.298
ema_dayEMA 6.:ema_beep_f4 -0.2109497 0.2146426 -0.983
ema_dayEMA 7.:ema_beep_f4 0.2532508 0.2191286 1.156
ema_dayEMA 2.:ema_beep_f5 0.1758335 0.2151572 0.817
ema_dayEMA 3.:ema_beep_f5 -0.0102118 0.2211402 -0.046
ema_dayEMA 4.:ema_beep_f5 0.0742144 0.2194411 0.338
ema_dayEMA 5.:ema_beep_f5 0.5792033 0.2254355 2.569
ema_dayEMA 6.:ema_beep_f5 0.2731363 0.2254783 1.211
ema_dayEMA 7.:ema_beep_f5 0.4974208 0.2252814 2.208
ema_dayEMA 2.:ema_beep_f6 0.1841992 0.2129285 0.865
ema_dayEMA 3.:ema_beep_f6 -0.1726791 0.2145978 -0.805
ema_dayEMA 4.:ema_beep_f6 -0.0806420 0.2146432 -0.376
ema_dayEMA 5.:ema_beep_f6 0.3063814 0.2148430 1.426
ema_dayEMA 6.:ema_beep_f6 0.3308938 0.2201258 1.503
ema_dayEMA 7.:ema_beep_f6 0.3920681 0.2480267 1.581
acc_delta:physical_excercise_dur -0.0143489 0.0229982 -0.624
Correlation matrix not shown by default, as p = 49 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
To make things readable, we present the results in a simpler table. Additionally, we also present a plot for visualization. This is the same plot that is presented in our paper as figure 2.
tab_model(glmer.event_week, glmer.activity_week, glmer.social_week, glmer.physical_week,
terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
dv.labels=c("Event", "Activity", "Social", "Physical"),
title="Table 1. Subjective Stress vs Week Type", show.df=T, show.fstat = T,
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Event | Activity | Social | Physical | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | df | Estimates | std. Error | CI | Statistic | p | df | Estimates | std. Error | CI | Statistic | p | df | Estimates | std. Error | CI | Statistic | p | df |
| (Intercept) | 5.59 | 0.14 | 5.31 – 5.86 | 39.95 | <0.001 | 5053.00 | 3.96 | 0.23 | 3.50 – 4.41 | 17.06 | <0.001 | 5053.00 | 1.45 | 0.04 | 1.36 – 1.53 | 33.32 | <0.001 | 5053.00 | 4.56 | 0.24 | 4.09 – 5.03 | 19.08 | <0.001 | 5053.00 |
| Week_Type [Stress] | 0.30 | 0.06 | 0.18 – 0.42 | 4.92 | <0.001 | 5053.00 | 0.47 | 0.10 | 0.27 – 0.67 | 4.71 | <0.001 | 5053.00 | 0.02 | 0.02 | -0.01 – 0.05 | 1.53 | 0.125 | 5053.00 | -0.06 | 0.09 | -0.24 – 0.12 | -0.67 | 0.505 | 5053.00 |
| Sex [Male] | 0.00 | 0.09 | -0.17 – 0.17 | 0.01 | 0.989 | 5053.00 | -0.04 | 0.15 | -0.34 – 0.26 | -0.24 | 0.812 | 5053.00 | 0.08 | 0.02 | 0.03 – 0.12 | 3.17 | 0.002 | 5053.00 | -0.30 | 0.21 | -0.71 – 0.11 | -1.43 | 0.152 | 5053.00 |
| Program [BSc_Med] | 0.01 | 0.10 | -0.18 – 0.20 | 0.11 | 0.914 | 5053.00 | 0.03 | 0.17 | -0.30 – 0.36 | 0.16 | 0.873 | 5053.00 | 0.01 | 0.03 | -0.04 – 0.06 | 0.44 | 0.661 | 5053.00 | -0.06 | 0.23 | -0.51 – 0.39 | -0.26 | 0.792 | 5053.00 |
| First_Week [Exam-First] | -0.08 | 0.09 | -0.25 – 0.10 | -0.87 | 0.386 | 5053.00 | 0.08 | 0.16 | -0.23 – 0.38 | 0.48 | 0.631 | 5053.00 | 0.03 | 0.02 | -0.02 – 0.08 | 1.16 | 0.248 | 5053.00 | 0.28 | 0.21 | -0.14 – 0.70 | 1.30 | 0.195 | 5053.00 |
| acc_delta | -0.00 | 0.00 | -0.01 – 0.01 | -0.22 | 0.824 | 5053.00 | -0.00 | 0.01 | -0.01 – 0.01 | -0.20 | 0.843 | 5053.00 | -0.00 | 0.00 | -0.00 – 0.00 | -1.17 | 0.243 | 5053.00 | -0.01 | 0.00 | -0.02 – -0.01 | -4.30 | <0.001 | 5053.00 |
| physical_excercise_dur | -0.30 | 0.17 | -0.62 – 0.03 | -1.78 | 0.075 | 5053.00 | 0.15 | 0.25 | -0.35 – 0.65 | 0.59 | 0.556 | 5053.00 | -0.07 | 0.06 | -0.18 – 0.04 | -1.25 | 0.211 | 5053.00 | 0.56 | 0.17 | 0.23 – 0.89 | 3.31 | 0.001 | 5053.00 |
| Random Effects | ||||||||||||||||||||||||
| σ2 | 1.33 | |||||||||||||||||||||||
| τ00 | 0.04 castor_record_id.ema_day.ema_beep_f | |||||||||||||||||||||||
| 0.04 castor_record_id | ||||||||||||||||||||||||
| 0.00 castor_record_id.1 | ||||||||||||||||||||||||
| 0.00 castor_record_id.2 | ||||||||||||||||||||||||
| 0.84 castor_record_id.3 | ||||||||||||||||||||||||
| τ11 | 0.61 castor_record_id.3.Week_TypeStress | |||||||||||||||||||||||
| ρ01 | -0.34 castor_record_id.3 | |||||||||||||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||||||
| 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | |||||||||||||||||||||
| 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | |||||||||||||||||||||
| Observations | 5110 | 5110 | 5110 | 5110 | ||||||||||||||||||||
| Marginal R2 / Conditional R2 | NA | NA | NA | 0.080 / NA | ||||||||||||||||||||
In the plot, we can see an increase in subjective stress measures for both event and activity realted stress during the exam week.
# Subset the variables we want to plot
plot.mood_week <- plot_models(glmer.event_week, glmer.activity_week, glmer.social_week, glmer.physical_week)
rm_term <- as.vector(plot.mood_week$data$term[1:length(plot.mood_week$data$term)])
rm_term <- rm_term[rm_term != "Week_TypeStress"]
# Make the plot
plot.mood_week <- plot_models(glmer.event_week, glmer.activity_week, glmer.social_week, glmer.physical_week,
m.labels=c("Event Stress", "Activity Stress","Social Stress", "Physical Stress" ),
axis.labels = c(" "),
# Stastistical Stuff
rm.terms = rm_term,
show.p=T,
p.shape=T,
legend.pval.title = "Significance",
# Visual Stuff
colors="#666666",
dot.size=2,
line.size = 1,
spacing=1 ,
vline.color = "darkgrey",
legend.title = "") + ylab("\nParameter Estimate (a.u.)") + xlab("Subjective Stress") +
ptheme +
theme(axis.ticks.y=element_blank(),
legend.text=element_text(size=16), legend.title = element_text(size=16),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
# Show and save
plot.mood_week+ coord_flip(ylim=c(-0.65,0.65)) + theme(panel.grid.major.y = element_line(colour = "grey95"), panel.grid.minor.y = element_line(colour = "grey90"))
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_WeekResid_SubjectiveStress.tiff",units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
Next, we want to look at the mood outcome measures for positive and negative mood. I used the same covariates as before, and the same approach to modeling. That is, I fit all possible families and links, and picked the best fit.
# Model
glmer.posmood_week <- glmer( mood_positive_s ~ Week_Type + #Model week
Sex + Program + # Model sex and program
First_Week + ema_day*ema_beep_f + # Model day related items
physical_excercise_dur + acc_delta + acc_delta*physical_excercise_dur + # Model movement
(1+Week_Type|castor_record_id) + (0+acc_delta|castor_record_id) +
(0+ema_survey|castor_record_id) + (0+physical_excercise_dur|castor_record_id) +
(1|castor_record_id:ema_day:ema_beep_f),
data=EMA_Data,
family=gaussian(link="log"),
control=lmerControl(calc.derivs = FALSE))
# Model Summary
summary(glmer.posmood_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: gaussian ( log )
Formula: mood_positive_s ~ Week_Type + Sex + Program + First_Week + ema_day * ema_beep_f + physical_excercise_dur + acc_delta + acc_delta *
physical_excercise_dur + (1 + Week_Type | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + ema_survey | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
17272.1 17644.8 -8579.0 17158.1 5053
Scaled residuals:
Min 1Q Median 3Q Max
-4.4607 -0.5933 0.0526 0.6165 4.1466
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 1.445e-09 3.801e-05
castor_record_id physical_excercise_dur 7.693e-07 8.771e-04
castor_record_id.1 ema_survey 6.776e-06 2.603e-03
castor_record_id.2 acc_delta 0.000e+00 0.000e+00
castor_record_id.3 (Intercept) 2.993e-02 1.730e-01
Week_TypeStress 1.444e-02 1.202e-01 -0.17
Residual 1.486e+00 1.219e+00
Number of obs: 5110, groups: castor_record_id:ema_day:ema_beep_f, 3069; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.8231525 0.0444471 41.019 < 2e-16 ***
Week_TypeStress -0.0770281 0.0145112 -5.308 1.11e-07 ***
SexMale 0.0463586 0.0403972 1.148 0.251146
ProgramBSc_Med 0.0205102 0.0443852 0.462 0.644013
First_WeekExam-First -0.0073609 0.0414660 -0.178 0.859103
ema_dayEMA 2. 0.0359134 0.0238576 1.505 0.132241
ema_dayEMA 3. -0.0084395 0.0248825 -0.339 0.734479
ema_dayEMA 4. -0.0002130 0.0253336 -0.008 0.993293
ema_dayEMA 5. 0.0065964 0.0257153 0.257 0.797551
ema_dayEMA 6. -0.0129383 0.0266128 -0.486 0.626848
ema_dayEMA 7. -0.0145495 0.0277341 -0.525 0.599855
ema_beep_f2 0.0189485 0.0238312 0.795 0.426547
ema_beep_f3 0.0310231 0.0235189 1.319 0.187145
ema_beep_f4 0.0245266 0.0237311 1.034 0.301362
ema_beep_f5 0.0900308 0.0243958 3.690 0.000224 ***
ema_beep_f6 0.0808752 0.0236408 3.421 0.000624 ***
physical_excercise_dur 0.0633148 0.0249673 2.536 0.011216 *
acc_delta 0.0012188 0.0005357 2.275 0.022890 *
ema_dayEMA 2.:ema_beep_f2 -0.0231506 0.0328963 -0.704 0.481592
ema_dayEMA 3.:ema_beep_f2 0.0102951 0.0338269 0.304 0.760863
ema_dayEMA 4.:ema_beep_f2 0.0008838 0.0342634 0.026 0.979421
ema_dayEMA 5.:ema_beep_f2 -0.0106469 0.0338654 -0.314 0.753227
ema_dayEMA 6.:ema_beep_f2 -0.0112518 0.0342189 -0.329 0.742293
ema_dayEMA 7.:ema_beep_f2 -0.0116784 0.0352622 -0.331 0.740503
ema_dayEMA 2.:ema_beep_f3 -0.0729524 0.0332003 -2.197 0.027996 *
ema_dayEMA 3.:ema_beep_f3 -0.0184629 0.0336525 -0.549 0.583256
ema_dayEMA 4.:ema_beep_f3 -0.0021692 0.0339030 -0.064 0.948983
ema_dayEMA 5.:ema_beep_f3 -0.0259461 0.0336814 -0.770 0.441099
ema_dayEMA 6.:ema_beep_f3 -0.0102841 0.0339227 -0.303 0.761766
ema_dayEMA 7.:ema_beep_f3 -0.0572074 0.0349988 -1.635 0.102143
ema_dayEMA 2.:ema_beep_f4 -0.0299963 0.0331047 -0.906 0.364880
ema_dayEMA 3.:ema_beep_f4 0.0270369 0.0333674 0.810 0.417780
ema_dayEMA 4.:ema_beep_f4 0.0049048 0.0338203 0.145 0.884690
ema_dayEMA 5.:ema_beep_f4 -0.0304746 0.0341575 -0.892 0.372297
ema_dayEMA 6.:ema_beep_f4 -0.0120031 0.0345190 -0.348 0.728047
ema_dayEMA 7.:ema_beep_f4 -0.0100683 0.0353250 -0.285 0.775629
ema_dayEMA 2.:ema_beep_f5 -0.0538986 0.0332010 -1.623 0.104503
ema_dayEMA 3.:ema_beep_f5 -0.0173217 0.0345140 -0.502 0.615756
ema_dayEMA 4.:ema_beep_f5 -0.0119120 0.0340266 -0.350 0.726280
ema_dayEMA 5.:ema_beep_f5 -0.0793808 0.0355805 -2.231 0.025680 *
ema_dayEMA 6.:ema_beep_f5 -0.0583661 0.0355166 -1.643 0.100311
ema_dayEMA 7.:ema_beep_f5 -0.0568634 0.0356347 -1.596 0.110549
ema_dayEMA 2.:ema_beep_f6 -0.0238617 0.0327344 -0.729 0.466033
ema_dayEMA 3.:ema_beep_f6 -0.0369972 0.0338226 -1.094 0.274016
ema_dayEMA 4.:ema_beep_f6 -0.0155267 0.0334988 -0.463 0.643007
ema_dayEMA 5.:ema_beep_f6 -0.0289097 0.0336308 -0.860 0.389999
ema_dayEMA 6.:ema_beep_f6 -0.0504028 0.0347243 -1.452 0.146637
ema_dayEMA 7.:ema_beep_f6 -0.0269167 0.0389139 -0.692 0.489127
physical_excercise_dur:acc_delta -0.0006480 0.0033907 -0.191 0.848432
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 49 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.negmood_week <- glmer( mood_negative_s ~ Week_Type + #Model week
Sex + Program + # Model sex and program
First_Week + ema_day*ema_beep_f + # Model day related items
physical_excercise_dur + acc_delta + acc_delta*physical_excercise_dur + # Model movement
(1+Week_Type|castor_record_id) + (0+acc_delta|castor_record_id) +
(0+ema_survey|castor_record_id) + (0+physical_excercise_dur|castor_record_id) +
(1|castor_record_id:ema_day:ema_beep_f),
data=EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE))
# Model Summary
summary(glmer.negmood_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: mood_negative_s ~ Week_Type + Sex + Program + First_Week + ema_day * ema_beep_f + physical_excercise_dur + acc_delta + acc_delta *
physical_excercise_dur + (1 + Week_Type | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + ema_survey | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
12044.8 12417.5 -5965.4 11930.8 5053
Scaled residuals:
Min 1Q Median 3Q Max
-2.3470 -0.5195 -0.0785 0.4418 5.5713
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 5.967e-02 0.244280
castor_record_id physical_excercise_dur 1.009e-01 0.317593
castor_record_id.1 ema_survey 1.501e-05 0.003874
castor_record_id.2 acc_delta 3.028e-05 0.005503
castor_record_id.3 (Intercept) 5.767e-02 0.240153
Week_TypeStress 3.491e-02 0.186837 -0.46
Residual 1.011e-01 0.317969
Number of obs: 5110, groups: castor_record_id:ema_day:ema_beep_f, 3069; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.031729 0.068715 15.015 < 2e-16 ***
Week_TypeStress 0.111470 0.022908 4.866 1.14e-06 ***
SexMale -0.206435 0.053294 -3.874 0.000107 ***
ProgramBSc_Med -0.128917 0.058583 -2.201 0.027767 *
First_WeekExam-First 0.060818 0.054650 1.113 0.265767
ema_dayEMA 2. -0.208437 0.057197 -3.644 0.000268 ***
ema_dayEMA 3. -0.183836 0.058442 -3.146 0.001657 **
ema_dayEMA 4. -0.194544 0.058761 -3.311 0.000930 ***
ema_dayEMA 5. -0.189802 0.058763 -3.230 0.001238 **
ema_dayEMA 6. -0.173772 0.060399 -2.877 0.004014 **
ema_dayEMA 7. -0.151262 0.061689 -2.452 0.014206 *
ema_beep_f2 -0.033504 0.057054 -0.587 0.557048
ema_beep_f3 -0.145839 0.056553 -2.579 0.009914 **
ema_beep_f4 -0.149544 0.056921 -2.627 0.008608 **
ema_beep_f5 -0.241366 0.059861 -4.032 5.53e-05 ***
ema_beep_f6 -0.300447 0.057901 -5.189 2.11e-07 ***
physical_excercise_dur -0.062434 0.068910 -0.906 0.364924
acc_delta -0.002835 0.001369 -2.071 0.038367 *
ema_dayEMA 2.:ema_beep_f2 0.073858 0.079779 0.926 0.354555
ema_dayEMA 3.:ema_beep_f2 0.053421 0.081423 0.656 0.511763
ema_dayEMA 4.:ema_beep_f2 0.013499 0.081763 0.165 0.868863
ema_dayEMA 5.:ema_beep_f2 0.042781 0.080679 0.530 0.595930
ema_dayEMA 6.:ema_beep_f2 0.022114 0.081258 0.272 0.785511
ema_dayEMA 7.:ema_beep_f2 -0.009783 0.083580 -0.117 0.906820
ema_dayEMA 2.:ema_beep_f3 0.189467 0.080187 2.363 0.018136 *
ema_dayEMA 3.:ema_beep_f3 0.140736 0.080607 1.746 0.080818 .
ema_dayEMA 4.:ema_beep_f3 0.131434 0.081156 1.620 0.105335
ema_dayEMA 5.:ema_beep_f3 0.146405 0.080393 1.821 0.068591 .
ema_dayEMA 6.:ema_beep_f3 0.142722 0.081258 1.756 0.079018 .
ema_dayEMA 7.:ema_beep_f3 0.206186 0.082048 2.513 0.011971 *
ema_dayEMA 2.:ema_beep_f4 0.215605 0.080382 2.682 0.007313 **
ema_dayEMA 3.:ema_beep_f4 0.124818 0.080617 1.548 0.121552
ema_dayEMA 4.:ema_beep_f4 0.155289 0.081062 1.916 0.055404 .
ema_dayEMA 5.:ema_beep_f4 0.174269 0.080886 2.154 0.031201 *
ema_dayEMA 6.:ema_beep_f4 0.164120 0.082050 2.000 0.045474 *
ema_dayEMA 7.:ema_beep_f4 0.153902 0.083469 1.844 0.065207 .
ema_dayEMA 2.:ema_beep_f5 0.233892 0.082226 2.845 0.004448 **
ema_dayEMA 3.:ema_beep_f5 0.126813 0.083866 1.512 0.130512
ema_dayEMA 4.:ema_beep_f5 0.227929 0.083437 2.732 0.006300 **
ema_dayEMA 5.:ema_beep_f5 0.237625 0.085158 2.790 0.005264 **
ema_dayEMA 6.:ema_beep_f5 0.229316 0.085716 2.675 0.007466 **
ema_dayEMA 7.:ema_beep_f5 0.216046 0.085174 2.537 0.011195 *
ema_dayEMA 2.:ema_beep_f6 0.270713 0.081194 3.334 0.000856 ***
ema_dayEMA 3.:ema_beep_f6 0.274803 0.081712 3.363 0.000771 ***
ema_dayEMA 4.:ema_beep_f6 0.240842 0.081668 2.949 0.003188 **
ema_dayEMA 5.:ema_beep_f6 0.294835 0.081609 3.613 0.000303 ***
ema_dayEMA 6.:ema_beep_f6 0.318424 0.083780 3.801 0.000144 ***
ema_dayEMA 7.:ema_beep_f6 0.349228 0.092832 3.762 0.000169 ***
physical_excercise_dur:acc_delta -0.008999 0.007994 -1.126 0.260277
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 49 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
convergence code: 0
failure to converge in 10000 evaluations
Next we present the table of the results. We present a plot later that shows the results for all the outcomes, but for now we simply print the results of the mixed models
tab_model(glmer.posmood_week, glmer.negmood_week,
terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
dv.labels=c("Positive", "Negative"),
title="Table 2. Mood vs Week Type",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Positive | Negative | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 1.82 | 0.04 | 1.74 – 1.91 | 41.02 | <0.001 | 1.03 | 0.07 | 0.90 – 1.17 | 15.01 | <0.001 |
| Week_Type [Stress] | -0.08 | 0.01 | -0.11 – -0.05 | -5.31 | <0.001 | 0.11 | 0.02 | 0.07 – 0.16 | 4.87 | <0.001 |
| Sex [Male] | 0.05 | 0.04 | -0.03 – 0.13 | 1.15 | 0.251 | -0.21 | 0.05 | -0.31 – -0.10 | -3.87 | <0.001 |
| Program [BSc_Med] | 0.02 | 0.04 | -0.07 – 0.11 | 0.46 | 0.644 | -0.13 | 0.06 | -0.24 – -0.01 | -2.20 | 0.028 |
| First_Week [Exam-First] | -0.01 | 0.04 | -0.09 – 0.07 | -0.18 | 0.859 | 0.06 | 0.05 | -0.05 – 0.17 | 1.11 | 0.266 |
| physical_excercise_dur | 0.06 | 0.02 | 0.01 – 0.11 | 2.54 | 0.011 | -0.06 | 0.07 | -0.20 – 0.07 | -0.91 | 0.365 |
| acc_delta | 0.00 | 0.00 | 0.00 – 0.00 | 2.28 | 0.023 | -0.00 | 0.00 | -0.01 – -0.00 | -2.07 | 0.038 |
| Random Effects | ||||||||||
| σ2 | 1.49 | |||||||||
| τ00 | 0.00 castor_record_id.ema_day.ema_beep_f | |||||||||
| 0.00 castor_record_id | ||||||||||
| 0.00 castor_record_id.1 | ||||||||||
| 0.00 castor_record_id.2 | ||||||||||
| 0.03 castor_record_id.3 | ||||||||||
| τ11 | 0.01 castor_record_id.3.Week_TypeStress | |||||||||
| ρ01 | -0.17 castor_record_id.3 | |||||||||
| N | 82 castor_record_id | 82 castor_record_id | ||||||||
| 7 ema_day | 7 ema_day | |||||||||
| 6 ema_beep_f | 6 ema_beep_f | |||||||||
| Observations | 5110 | 5110 | ||||||||
| Marginal R2 / Conditional R2 | 0.002 / NA | NA | ||||||||
We also want to see if theres a general difference between the physiology variables and the weeks.To do this we build separate models for each physiology data feature. We also model the same covariates from before, but we also add to them temperature related changes, as we expect these to be highly singificant and related to our physiology. We present the results for the skin conductance and heart rate separately, and then together with FDR correction.
First we model the skin conductance, controlling for skin temparature. It looks like there is a big difference between the weeks, though not in the expected direction. For each model, we sekected the best family and link fit and present those below.
# Model
glmer.sc_ton_mean_week <- glmer( sc_tonic_mean_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur + acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Pub,
family=Gamma(link="log"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.sc_ton_mean_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: sc_tonic_mean_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Pub
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
-1405.7 -1022.7 761.8 -1523.7 4812
Scaled residuals:
Min 1Q Median 3Q Max
-3.4589 -0.2899 -0.0689 0.1329 9.3566
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.025340 0.159184
castor_record_id acc_delta 0.000078 0.008832
castor_record_id.1 physical_excercise_dur 0.029822 0.172690
castor_record_id.2 temp_mean_z 0.002067 0.045464
castor_record_id.3 temp_slope_z 0.003169 0.056292
castor_record_id.4 (Intercept) 0.003159 0.056208
Week_TypeStress 0.005701 0.075503 -0.85
Residual 0.031393 0.177182
Number of obs: 4871, groups: castor_record_id:ema_day:ema_beep_f, 2985; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.1039732 0.0281128 3.698 0.000217 ***
Week_TypeStress -0.0077766 0.0102403 -0.759 0.447605
SexMale 0.0005708 0.0129481 0.044 0.964836
ProgramP2 -0.0369714 0.0142713 -2.591 0.009581 **
First_WeekExam-First -0.0375530 0.0132528 -2.834 0.004603 **
ema_beep_f2 -0.0120914 0.0356987 -0.339 0.734831
ema_beep_f3 0.0177033 0.0352335 0.502 0.615346
ema_beep_f4 -0.0142781 0.0354812 -0.402 0.687380
ema_beep_f5 -0.0120938 0.0370798 -0.326 0.744307
ema_beep_f6 0.0362003 0.0361193 1.002 0.316226
ema_dayEMA 2. -0.0060416 0.0357477 -0.169 0.865792
ema_dayEMA 3. -0.0625819 0.0361515 -1.731 0.083434 .
ema_dayEMA 4. -0.0193552 0.0361262 -0.536 0.592121
ema_dayEMA 5. -0.0644634 0.0360596 -1.788 0.073826 .
ema_dayEMA 6. -0.0405873 0.0369004 -1.100 0.271369
ema_dayEMA 7. -0.0486189 0.0368952 -1.318 0.187584
physical_excercise_dur 0.0578554 0.0323015 1.791 0.073276 .
acc_delta 0.0125550 0.0012642 9.931 < 2e-16 ***
temp_mean_z 0.0213790 0.0067952 3.146 0.001654 **
temp_slope_z 0.0224963 0.0080180 2.806 0.005020 **
ema_beep_f2:ema_dayEMA 2. -0.0207045 0.0498834 -0.415 0.678100
ema_beep_f3:ema_dayEMA 2. 0.0057906 0.0499772 0.116 0.907760
ema_beep_f4:ema_dayEMA 2. -0.0123862 0.0501674 -0.247 0.804988
ema_beep_f5:ema_dayEMA 2. -0.0476772 0.0511883 -0.931 0.351643
ema_beep_f6:ema_dayEMA 2. -0.0553247 0.0506377 -1.093 0.274587
ema_beep_f2:ema_dayEMA 3. 0.0204893 0.0506728 0.404 0.685959
ema_beep_f3:ema_dayEMA 3. -0.0075935 0.0501722 -0.151 0.879700
ema_beep_f4:ema_dayEMA 3. 0.0175097 0.0500830 0.350 0.726629
ema_beep_f5:ema_dayEMA 3. 0.0454917 0.0519473 0.876 0.381178
ema_beep_f6:ema_dayEMA 3. 0.0257633 0.0506955 0.508 0.611315
ema_beep_f2:ema_dayEMA 4. -0.0257218 0.0508428 -0.506 0.612922
ema_beep_f3:ema_dayEMA 4. -0.0753644 0.0503573 -1.497 0.134499
ema_beep_f4:ema_dayEMA 4. -0.0352737 0.0503054 -0.701 0.483184
ema_beep_f5:ema_dayEMA 4. -0.0134256 0.0515284 -0.261 0.794442
ema_beep_f6:ema_dayEMA 4. -0.0661724 0.0506176 -1.307 0.191111
ema_beep_f2:ema_dayEMA 5. 0.0286201 0.0503263 0.569 0.569566
ema_beep_f3:ema_dayEMA 5. 0.0069213 0.0499645 0.139 0.889826
ema_beep_f4:ema_dayEMA 5. 0.0094873 0.0503138 0.189 0.850437
ema_beep_f5:ema_dayEMA 5. -0.0066590 0.0531778 -0.125 0.900349
ema_beep_f6:ema_dayEMA 5. -0.0011590 0.0507614 -0.023 0.981784
ema_beep_f2:ema_dayEMA 6. 0.0091557 0.0508887 0.180 0.857218
ema_beep_f3:ema_dayEMA 6. -0.0236810 0.0506816 -0.467 0.640321
ema_beep_f4:ema_dayEMA 6. -0.0165692 0.0512936 -0.323 0.746675
ema_beep_f5:ema_dayEMA 6. -0.0050347 0.0532600 -0.095 0.924687
ema_beep_f6:ema_dayEMA 6. -0.0412898 0.0521794 -0.791 0.428767
ema_beep_f2:ema_dayEMA 7. 0.0142632 0.0518275 0.275 0.783159
ema_beep_f3:ema_dayEMA 7. -0.0051180 0.0508239 -0.101 0.919788
ema_beep_f4:ema_dayEMA 7. 0.0357892 0.0517982 0.691 0.489606
ema_beep_f5:ema_dayEMA 7. 0.0174751 0.0527506 0.331 0.740435
ema_beep_f6:ema_dayEMA 7. -0.0444276 0.0573065 -0.775 0.438185
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.sc_ph_num <- glmer( sc_phasic_num ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur + acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=poisson(link="log"),
control=lmerControl(calc.derivs = FALSE) )
# Model Summary
summary(glmer.sc_ph_num)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: sc_phasic_num ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
47853.3 48229.8 -23868.6 47737.3 4813
Scaled residuals:
Min 1Q Median 3Q Max
-6.35 -0.98 -0.13 0.61 2852.96
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 1.55083 1.2453
castor_record_id acc_delta 0.01408 0.1187
castor_record_id.1 physical_excercise_dur 7.07199 2.6593
castor_record_id.2 temp_mean_z 0.35415 0.5951
castor_record_id.3 temp_slope_z 0.22974 0.4793
castor_record_id.4 (Intercept) 1.13258 1.0642
Week_TypeStress 0.48157 0.6940 -0.25
Number of obs: 4871, groups: castor_record_id:ema_day:ema_beep_f, 2985; castor_record_id, 82
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.523675 0.296412 5.140 2.74e-07 ***
Week_TypeStress -0.277404 0.079256 -3.500 0.000465 ***
SexMale 0.411508 0.245432 1.677 0.093607 .
ProgramBSc_Med 0.131599 0.270989 0.486 0.627232
First_WeekExam-First 0.035360 0.252223 0.140 0.888506
ema_beep_f2 -0.011745 0.216371 -0.054 0.956711
ema_beep_f3 -0.268295 0.213526 -1.256 0.208935
ema_beep_f4 -0.456449 0.217091 -2.103 0.035503 *
ema_beep_f5 -0.481962 0.225426 -2.138 0.032516 *
ema_beep_f6 -0.318057 0.219996 -1.446 0.148250
ema_dayEMA 2. -0.110218 0.217110 -0.508 0.611691
ema_dayEMA 3. -0.547372 0.220549 -2.482 0.013070 *
ema_dayEMA 4. -0.580820 0.218951 -2.653 0.007984 **
ema_dayEMA 5. -0.600885 0.219100 -2.743 0.006097 **
ema_dayEMA 6. -0.437176 0.225205 -1.941 0.052230 .
ema_dayEMA 7. -0.500067 0.223759 -2.235 0.025427 *
physical_excercise_dur 0.065567 0.321188 0.204 0.838246
acc_delta 0.145693 0.013506 10.787 < 2e-16 ***
temp_mean_z 0.315208 0.068331 4.613 3.97e-06 ***
temp_slope_z 0.192522 0.056122 3.430 0.000603 ***
ema_beep_f2:ema_dayEMA 2. -0.305653 0.304289 -1.004 0.315145
ema_beep_f3:ema_dayEMA 2. 0.092300 0.303511 0.304 0.761045
ema_beep_f4:ema_dayEMA 2. 0.244280 0.306453 0.797 0.425382
ema_beep_f5:ema_dayEMA 2. 0.082331 0.312866 0.263 0.792435
ema_beep_f6:ema_dayEMA 2. -0.575847 0.312028 -1.845 0.064965 .
ema_beep_f2:ema_dayEMA 3. 0.200729 0.309550 0.648 0.516692
ema_beep_f3:ema_dayEMA 3. 0.414335 0.306314 1.353 0.176168
ema_beep_f4:ema_dayEMA 3. 0.466277 0.307134 1.518 0.128976
ema_beep_f5:ema_dayEMA 3. 0.488258 0.317028 1.540 0.123533
ema_beep_f6:ema_dayEMA 3. 0.303923 0.311133 0.977 0.328656
ema_beep_f2:ema_dayEMA 4. 0.102194 0.310083 0.330 0.741724
ema_beep_f3:ema_dayEMA 4. 0.216596 0.307691 0.704 0.481470
ema_beep_f4:ema_dayEMA 4. 0.483253 0.308373 1.567 0.117090
ema_beep_f5:ema_dayEMA 4. 0.444842 0.315535 1.410 0.158598
ema_beep_f6:ema_dayEMA 4. 0.189572 0.311614 0.608 0.542951
ema_beep_f2:ema_dayEMA 5. -0.106392 0.307793 -0.346 0.729597
ema_beep_f3:ema_dayEMA 5. 0.324091 0.306169 1.059 0.289811
ema_beep_f4:ema_dayEMA 5. 0.599767 0.307864 1.948 0.051396 .
ema_beep_f5:ema_dayEMA 5. 0.096859 0.325250 0.298 0.765858
ema_beep_f6:ema_dayEMA 5. -0.001503 0.313446 -0.005 0.996175
ema_beep_f2:ema_dayEMA 6. 0.017425 0.311119 0.056 0.955337
ema_beep_f3:ema_dayEMA 6. 0.244953 0.310796 0.788 0.430610
ema_beep_f4:ema_dayEMA 6. 0.303635 0.314886 0.964 0.334911
ema_beep_f5:ema_dayEMA 6. 0.190439 0.326884 0.583 0.560170
ema_beep_f6:ema_dayEMA 6. -0.161854 0.322898 -0.501 0.616193
ema_beep_f2:ema_dayEMA 7. 0.188897 0.314941 0.600 0.548650
ema_beep_f3:ema_dayEMA 7. 0.254727 0.310815 0.820 0.412475
ema_beep_f4:ema_dayEMA 7. 0.207454 0.318416 0.652 0.514711
ema_beep_f5:ema_dayEMA 7. -0.024657 0.322544 -0.076 0.939064
ema_beep_f6:ema_dayEMA 7. 0.110373 0.348213 0.317 0.751267
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.sc_ph_mag <- glmer( sc_phasic_mag_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur +acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
# Model Summary
summary(glmer.sc_ph_mag)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: sc_phasic_mag_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
11102.2 11485.2 -5492.1 10984.2 4812
Scaled residuals:
Min 1Q Median 3Q Max
-2.1393 -0.5111 -0.0753 0.4612 5.1547
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.264007 0.51382
castor_record_id acc_delta 0.001006 0.03172
castor_record_id.1 physical_excercise_dur 0.249678 0.49968
castor_record_id.2 temp_mean_z 0.018295 0.13526
castor_record_id.3 temp_slope_z 0.013368 0.11562
castor_record_id.4 (Intercept) 0.071972 0.26828
Week_TypeStress 0.094414 0.30727 -0.70
Residual 0.115606 0.34001
Number of obs: 4871, groups: castor_record_id:ema_day:ema_beep_f, 2985; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 2.093246 0.115226 18.166 < 2e-16 ***
Week_TypeStress -0.072225 0.040948 -1.764 0.077760 .
SexMale 0.095661 0.059135 1.618 0.105736
ProgramBSc_Med -0.005529 0.065055 -0.085 0.932266
First_WeekExam-First -0.011885 0.060522 -0.196 0.844318
ema_beep_f2 -0.060104 0.130928 -0.459 0.646193
ema_beep_f3 -0.059550 0.129908 -0.458 0.646666
ema_beep_f4 -0.110365 0.129911 -0.850 0.395579
ema_beep_f5 -0.221627 0.133360 -1.662 0.096540 .
ema_beep_f6 -0.023463 0.131712 -0.178 0.858614
ema_dayEMA 2. -0.111098 0.130270 -0.853 0.393752
ema_dayEMA 3. -0.206161 0.130914 -1.575 0.115305
ema_dayEMA 4. -0.127115 0.131401 -0.967 0.333352
ema_dayEMA 5. -0.190647 0.129539 -1.472 0.141095
ema_dayEMA 6. -0.177423 0.132971 -1.334 0.182105
ema_dayEMA 7. -0.094416 0.135203 -0.698 0.484971
physical_excercise_dur 0.252229 0.109263 2.308 0.020973 *
acc_delta 0.102322 0.005050 20.263 < 2e-16 ***
temp_mean_z 0.081751 0.022762 3.592 0.000329 ***
temp_slope_z 0.071418 0.022305 3.202 0.001365 **
ema_beep_f2:ema_dayEMA 2. 0.067655 0.181341 0.373 0.709088
ema_beep_f3:ema_dayEMA 2. 0.201175 0.184299 1.092 0.275023
ema_beep_f4:ema_dayEMA 2. 0.070759 0.181796 0.389 0.697113
ema_beep_f5:ema_dayEMA 2. 0.185545 0.183532 1.011 0.312033
ema_beep_f6:ema_dayEMA 2. -0.093371 0.180503 -0.517 0.604959
ema_beep_f2:ema_dayEMA 3. 0.081457 0.182670 0.446 0.655654
ema_beep_f3:ema_dayEMA 3. 0.066165 0.181212 0.365 0.715018
ema_beep_f4:ema_dayEMA 3. 0.143242 0.180705 0.793 0.427960
ema_beep_f5:ema_dayEMA 3. 0.212893 0.184544 1.154 0.248658
ema_beep_f6:ema_dayEMA 3. 0.184762 0.182242 1.014 0.310667
ema_beep_f2:ema_dayEMA 4. 0.043410 0.183713 0.236 0.813207
ema_beep_f3:ema_dayEMA 4. 0.031317 0.182296 0.172 0.863600
ema_beep_f4:ema_dayEMA 4. -0.005062 0.180792 -0.028 0.977661
ema_beep_f5:ema_dayEMA 4. 0.166133 0.183680 0.904 0.365746
ema_beep_f6:ema_dayEMA 4. -0.107581 0.180147 -0.597 0.550384
ema_beep_f2:ema_dayEMA 5. -0.010541 0.179333 -0.059 0.953130
ema_beep_f3:ema_dayEMA 5. 0.049086 0.179319 0.274 0.784286
ema_beep_f4:ema_dayEMA 5. 0.157847 0.181273 0.871 0.383882
ema_beep_f5:ema_dayEMA 5. 0.187414 0.188383 0.995 0.319805
ema_beep_f6:ema_dayEMA 5. -0.072172 0.179292 -0.403 0.687289
ema_beep_f2:ema_dayEMA 6. 0.161451 0.184067 0.877 0.380416
ema_beep_f3:ema_dayEMA 6. 0.078590 0.182438 0.431 0.666631
ema_beep_f4:ema_dayEMA 6. 0.110882 0.183722 0.604 0.546153
ema_beep_f5:ema_dayEMA 6. 0.239192 0.189040 1.265 0.205765
ema_beep_f6:ema_dayEMA 6. -0.066544 0.183993 -0.362 0.717602
ema_beep_f2:ema_dayEMA 7. 0.142784 0.189780 0.752 0.451833
ema_beep_f3:ema_dayEMA 7. -0.020486 0.184394 -0.111 0.911538
ema_beep_f4:ema_dayEMA 7. 0.023701 0.187879 0.126 0.899613
ema_beep_f5:ema_dayEMA 7. 0.002820 0.187815 0.015 0.988021
ema_beep_f6:ema_dayEMA 7. -0.037235 0.204576 -0.182 0.855574
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.sc_ph_auc_week <- glmer( sc_phasic_auc_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur +acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=Gamma(link=log),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.sc_ph_auc_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: sc_phasic_auc_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
8774.4 9157.4 -4328.2 8656.4 4812
Scaled residuals:
Min 1Q Median 3Q Max
-2.2859 -0.4668 -0.1553 0.2620 4.5998
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.0895855 0.29931
castor_record_id acc_delta 0.0002871 0.01694
castor_record_id.1 physical_excercise_dur 0.0820159 0.28638
castor_record_id.2 temp_mean_z 0.0080251 0.08958
castor_record_id.3 temp_slope_z 0.0082019 0.09056
castor_record_id.4 (Intercept) 0.0216869 0.14726
Week_TypeStress 0.0249042 0.15781 -0.64
Residual 0.1171402 0.34226
Number of obs: 4871, groups: castor_record_id:ema_day:ema_beep_f, 2985; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.388492 0.061034 6.365 1.95e-10 ***
Week_TypeStress -0.060887 0.020911 -2.912 0.00359 **
SexMale 0.012285 0.033666 0.365 0.71518
ProgramBSc_Med 0.014510 0.037136 0.391 0.69601
First_WeekExam-First -0.034996 0.034550 -1.013 0.31110
ema_beep_f2 -0.060557 0.067910 -0.892 0.37254
ema_beep_f3 -0.032083 0.067033 -0.479 0.63221
ema_beep_f4 -0.157141 0.067499 -2.328 0.01991 *
ema_beep_f5 -0.142661 0.070590 -2.021 0.04328 *
ema_beep_f6 -0.014964 0.068758 -0.218 0.82772
ema_dayEMA 2. -0.020134 0.068014 -0.296 0.76721
ema_dayEMA 3. -0.175363 0.068832 -2.548 0.01084 *
ema_dayEMA 4. -0.180634 0.068761 -2.627 0.00861 **
ema_dayEMA 5. -0.190408 0.068637 -2.774 0.00554 **
ema_dayEMA 6. -0.174990 0.070238 -2.491 0.01273 *
ema_dayEMA 7. -0.150953 0.070240 -2.149 0.03163 *
physical_excercise_dur 0.067279 0.058161 1.157 0.24737
acc_delta 0.038351 0.002432 15.771 < 2e-16 ***
temp_mean_z 0.065834 0.013469 4.888 1.02e-06 ***
temp_slope_z 0.044050 0.013787 3.195 0.00140 **
ema_beep_f2:ema_dayEMA 2. -0.014153 0.094906 -0.149 0.88145
ema_beep_f3:ema_dayEMA 2. -0.023035 0.095075 -0.242 0.80856
ema_beep_f4:ema_dayEMA 2. 0.038281 0.095443 0.401 0.68836
ema_beep_f5:ema_dayEMA 2. 0.025079 0.097405 0.257 0.79681
ema_beep_f6:ema_dayEMA 2. -0.179572 0.096357 -1.864 0.06238 .
ema_beep_f2:ema_dayEMA 3. 0.109953 0.096395 1.141 0.25401
ema_beep_f3:ema_dayEMA 3. 0.036368 0.095491 0.381 0.70331
ema_beep_f4:ema_dayEMA 3. 0.172527 0.095298 1.810 0.07023 .
ema_beep_f5:ema_dayEMA 3. 0.184727 0.098905 1.868 0.06180 .
ema_beep_f6:ema_dayEMA 3. 0.112934 0.096504 1.170 0.24190
ema_beep_f2:ema_dayEMA 4. 0.155081 0.096723 1.603 0.10886
ema_beep_f3:ema_dayEMA 4. 0.051746 0.095831 0.540 0.58922
ema_beep_f4:ema_dayEMA 4. 0.162519 0.095714 1.698 0.08951 .
ema_beep_f5:ema_dayEMA 4. 0.155729 0.098066 1.588 0.11228
ema_beep_f6:ema_dayEMA 4. 0.002540 0.096318 0.026 0.97896
ema_beep_f2:ema_dayEMA 5. 0.071225 0.095751 0.744 0.45696
ema_beep_f3:ema_dayEMA 5. 0.078734 0.095070 0.828 0.40758
ema_beep_f4:ema_dayEMA 5. 0.217518 0.095739 2.272 0.02309 *
ema_beep_f5:ema_dayEMA 5. 0.083740 0.101236 0.827 0.40814
ema_beep_f6:ema_dayEMA 5. 0.055089 0.096615 0.570 0.56855
ema_beep_f2:ema_dayEMA 6. 0.126453 0.096835 1.306 0.19160
ema_beep_f3:ema_dayEMA 6. 0.079257 0.096455 0.822 0.41125
ema_beep_f4:ema_dayEMA 6. 0.148516 0.097619 1.521 0.12816
ema_beep_f5:ema_dayEMA 6. 0.122388 0.101392 1.207 0.22740
ema_beep_f6:ema_dayEMA 6. 0.054131 0.099315 0.545 0.58572
ema_beep_f2:ema_dayEMA 7. 0.099943 0.098605 1.014 0.31079
ema_beep_f3:ema_dayEMA 7. 0.061271 0.096719 0.634 0.52641
ema_beep_f4:ema_dayEMA 7. 0.141078 0.098593 1.431 0.15245
ema_beep_f5:ema_dayEMA 7. 0.006557 0.100436 0.065 0.94795
ema_beep_f6:ema_dayEMA 7. 0.031370 0.109115 0.287 0.77373
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
Hear we can see that overall the measures seem to go down. We still need to correct for multiple comparrisons, but we can do this at the end when we also factor in our heart rate models to also include that informaiton in the FDR correction.
tab_model(glmer.sc_ton_mean_week, glmer.sc_ph_num, glmer.sc_ph_mag, glmer.sc_ph_auc_week,
terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
dv.labels=c("Tonic", "Number", "Magnitude", "AUC"),
title="Table 3. SC vs Week Type",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Tonic | Number | Magnitude | AUC | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Log-Mean | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.10 | 0.03 | 0.05 – 0.16 | 3.70 | <0.001 | 1.52 | 0.30 | 0.94 – 2.10 | 5.14 | <0.001 | 2.09 | 0.12 | 1.87 – 2.32 | 18.17 | <0.001 | 0.39 | 0.06 | 0.27 – 0.51 | 6.37 | <0.001 |
| Week_Type [Stress] | -0.01 | 0.01 | -0.03 – 0.01 | -0.76 | 0.448 | -0.28 | 0.08 | -0.43 – -0.12 | -3.50 | <0.001 | -0.07 | 0.04 | -0.15 – 0.01 | -1.76 | 0.078 | -0.06 | 0.02 | -0.10 – -0.02 | -2.91 | 0.004 |
| Sex [Male] | 0.00 | 0.01 | -0.02 – 0.03 | 0.04 | 0.965 | 0.41 | 0.25 | -0.07 – 0.89 | 1.68 | 0.094 | 0.10 | 0.06 | -0.02 – 0.21 | 1.62 | 0.106 | 0.01 | 0.03 | -0.05 – 0.08 | 0.36 | 0.715 |
| First_Week [Exam-First] | -0.04 | 0.01 | -0.06 – -0.01 | -2.83 | 0.005 | 0.04 | 0.25 | -0.46 – 0.53 | 0.14 | 0.889 | -0.01 | 0.06 | -0.13 – 0.11 | -0.20 | 0.844 | -0.03 | 0.03 | -0.10 – 0.03 | -1.01 | 0.311 |
| physical_excercise_dur | 0.06 | 0.03 | -0.01 – 0.12 | 1.79 | 0.073 | 0.07 | 0.32 | -0.56 – 0.70 | 0.20 | 0.838 | 0.25 | 0.11 | 0.04 – 0.47 | 2.31 | 0.021 | 0.07 | 0.06 | -0.05 – 0.18 | 1.16 | 0.247 |
| acc_delta | 0.01 | 0.00 | 0.01 – 0.02 | 9.93 | <0.001 | 0.15 | 0.01 | 0.12 – 0.17 | 10.79 | <0.001 | 0.10 | 0.01 | 0.09 – 0.11 | 20.26 | <0.001 | 0.04 | 0.00 | 0.03 – 0.04 | 15.77 | <0.001 |
| Program [BSc_Med] | 0.13 | 0.27 | -0.40 – 0.66 | 0.49 | 0.627 | -0.01 | 0.07 | -0.13 – 0.12 | -0.08 | 0.932 | 0.01 | 0.04 | -0.06 – 0.09 | 0.39 | 0.696 | |||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||
| 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | |||||||||||||||||
| 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | |||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | ||||||||||||||||
We now take a look at the heart rate models. As the IBI data was way too sparse, it would be difficult to analyze the temporal domain changes. So we stick to simple measures of heart rate from the E4. Again, we fit the different families and links, and present the optimal fits below.
# Model
glmer.hr_mean_week <- glmer( hr_mean_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur +acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=Gamma(link=identity),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.hr_mean_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: hr_mean_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
7540.8 7921.8 -3711.4 7422.8 4652
Scaled residuals:
Min 1Q Median 3Q Max
-3.6174 -0.5158 -0.0471 0.4478 7.3365
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.1576115 0.39700
castor_record_id acc_delta 0.0009036 0.03006
castor_record_id.1 physical_excercise_dur 0.1658048 0.40719
castor_record_id.2 temp_mean_z 0.0239130 0.15464
castor_record_id.3 temp_slope_z 0.0176056 0.13269
castor_record_id.4 (Intercept) 0.0614173 0.24783
Week_TypeStress 0.0369784 0.19230 -0.52
Residual 0.0193458 0.13909
Number of obs: 4711, groups: castor_record_id:ema_day:ema_beep_f, 2958; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 3.258e+00 9.176e-02 35.510 < 2e-16 ***
Week_TypeStress -5.645e-02 2.683e-02 -2.104 0.035364 *
SexMale -5.306e-02 5.801e-02 -0.915 0.360282
ProgramBSc_Med 1.327e-01 6.325e-02 2.098 0.035921 *
First_WeekExam-First 1.170e-01 5.926e-02 1.975 0.048290 *
ema_beep_f2 -2.979e-02 9.489e-02 -0.314 0.753560
ema_beep_f3 -2.552e-02 9.450e-02 -0.270 0.787094
ema_beep_f4 6.431e-02 9.596e-02 0.670 0.502775
ema_beep_f5 3.320e-03 1.001e-01 0.033 0.973547
ema_beep_f6 -3.340e-01 9.290e-02 -3.595 0.000325 ***
ema_dayEMA 2. 1.572e-03 9.490e-02 0.017 0.986788
ema_dayEMA 3. -4.255e-02 9.763e-02 -0.436 0.662965
ema_dayEMA 4. -1.048e-02 9.726e-02 -0.108 0.914158
ema_dayEMA 5. -7.373e-02 9.492e-02 -0.777 0.437296
ema_dayEMA 6. 2.035e-02 9.899e-02 0.206 0.837104
ema_dayEMA 7. -4.639e-02 9.896e-02 -0.469 0.639195
physical_excercise_dur 5.028e-01 8.337e-02 6.031 1.63e-09 ***
acc_delta 1.292e-01 4.386e-03 29.451 < 2e-16 ***
temp_mean_z -4.341e-02 2.211e-02 -1.963 0.049646 *
temp_slope_z 3.394e-02 2.118e-02 1.602 0.109098
ema_beep_f2:ema_dayEMA 2. 7.520e-02 1.334e-01 0.564 0.573021
ema_beep_f3:ema_dayEMA 2. 1.439e-02 1.343e-01 0.107 0.914687
ema_beep_f4:ema_dayEMA 2. 6.156e-02 1.358e-01 0.453 0.650418
ema_beep_f5:ema_dayEMA 2. 3.539e-03 1.366e-01 0.026 0.979333
ema_beep_f6:ema_dayEMA 2. 3.856e-02 1.296e-01 0.298 0.766002
ema_beep_f2:ema_dayEMA 3. 9.751e-02 1.365e-01 0.714 0.474998
ema_beep_f3:ema_dayEMA 3. 9.660e-04 1.349e-01 0.007 0.994289
ema_beep_f4:ema_dayEMA 3. 2.665e-02 1.366e-01 0.195 0.845391
ema_beep_f5:ema_dayEMA 3. -1.713e-02 1.398e-01 -0.123 0.902448
ema_beep_f6:ema_dayEMA 3. 1.730e-02 1.309e-01 0.132 0.894853
ema_beep_f2:ema_dayEMA 4. -6.651e-03 1.367e-01 -0.049 0.961203
ema_beep_f3:ema_dayEMA 4. 3.250e-02 1.361e-01 0.239 0.811212
ema_beep_f4:ema_dayEMA 4. -5.490e-02 1.370e-01 -0.401 0.688535
ema_beep_f5:ema_dayEMA 4. 1.869e-02 1.389e-01 0.135 0.893001
ema_beep_f6:ema_dayEMA 4. 3.422e-02 1.311e-01 0.261 0.794093
ema_beep_f2:ema_dayEMA 5. 8.250e-02 1.327e-01 0.622 0.534262
ema_beep_f3:ema_dayEMA 5. 1.017e-01 1.339e-01 0.759 0.447569
ema_beep_f4:ema_dayEMA 5. -2.056e-02 1.346e-01 -0.153 0.878602
ema_beep_f5:ema_dayEMA 5. 1.397e-02 1.405e-01 0.099 0.920821
ema_beep_f6:ema_dayEMA 5. 1.603e-02 1.294e-01 0.124 0.901389
ema_beep_f2:ema_dayEMA 6. 8.107e-02 1.361e-01 0.596 0.551292
ema_beep_f3:ema_dayEMA 6. -1.189e-02 1.358e-01 -0.088 0.930242
ema_beep_f4:ema_dayEMA 6. 2.460e-03 1.386e-01 0.018 0.985844
ema_beep_f5:ema_dayEMA 6. -1.650e-01 1.423e-01 -1.160 0.246061
ema_beep_f6:ema_dayEMA 6. -1.297e-01 1.335e-01 -0.972 0.331285
ema_beep_f2:ema_dayEMA 7. 5.110e-02 1.380e-01 0.370 0.711229
ema_beep_f3:ema_dayEMA 7. 5.378e-02 1.363e-01 0.395 0.693200
ema_beep_f4:ema_dayEMA 7. 9.676e-05 1.407e-01 0.001 0.999451
ema_beep_f5:ema_dayEMA 7. 5.961e-02 1.411e-01 0.422 0.672675
ema_beep_f6:ema_dayEMA 7. 2.207e-01 1.478e-01 1.494 0.135247
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.hr_max_week <- glmer( hr_max_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur +acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model SUmmary
summary(glmer.hr_max_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: hr_max_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
11059.0 11440.0 -5470.5 10941.0 4652
Scaled residuals:
Min 1Q Median 3Q Max
-3.5142 -0.5339 -0.0941 0.4672 5.3176
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.321320 0.56685
castor_record_id acc_delta 0.001173 0.03425
castor_record_id.1 physical_excercise_dur 0.265895 0.51565
castor_record_id.2 temp_mean_z 0.031866 0.17851
castor_record_id.3 temp_slope_z 0.020873 0.14447
castor_record_id.4 (Intercept) 0.056195 0.23705
Week_TypeStress 0.041653 0.20409 -0.65
Residual 0.032039 0.17900
Number of obs: 4711, groups: castor_record_id:ema_day:ema_beep_f, 2958; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 3.610979 0.117646 30.694 < 2e-16 ***
Week_TypeStress -0.102658 0.032271 -3.181 0.001467 **
SexMale 0.089559 0.059713 1.500 0.133663
ProgramBSc_Med 0.070230 0.064731 1.085 0.277942
First_WeekExam-First 0.111305 0.060799 1.831 0.067143 .
ema_beep_f2 -0.074871 0.136659 -0.548 0.583782
ema_beep_f3 -0.078602 0.136110 -0.577 0.563609
ema_beep_f4 0.037330 0.138516 0.269 0.787547
ema_beep_f5 -0.021750 0.144295 -0.151 0.880187
ema_beep_f6 -0.460252 0.132760 -3.467 0.000527 ***
ema_dayEMA 2. -0.068711 0.136734 -0.503 0.615302
ema_dayEMA 3. -0.132848 0.140371 -0.946 0.343939
ema_dayEMA 4. 0.004396 0.140826 0.031 0.975100
ema_dayEMA 5. -0.284643 0.135693 -2.098 0.035932 *
ema_dayEMA 6. -0.006776 0.142700 -0.047 0.962129
ema_dayEMA 7. -0.004806 0.143771 -0.033 0.973334
physical_excercise_dur 0.427944 0.113795 3.761 0.000169 ***
acc_delta 0.159653 0.005583 28.598 < 2e-16 ***
temp_mean_z -0.174829 0.027468 -6.365 1.95e-10 ***
temp_slope_z 0.027687 0.026663 1.038 0.299092
ema_beep_f2:ema_dayEMA 2. 0.174511 0.192231 0.908 0.363973
ema_beep_f3:ema_dayEMA 2. 0.141258 0.193521 0.730 0.465429
ema_beep_f4:ema_dayEMA 2. 0.016042 0.195262 0.082 0.934524
ema_beep_f5:ema_dayEMA 2. 0.097199 0.196780 0.494 0.621342
ema_beep_f6:ema_dayEMA 2. 0.224705 0.185588 1.211 0.225983
ema_beep_f2:ema_dayEMA 3. 0.186199 0.196239 0.949 0.342704
ema_beep_f3:ema_dayEMA 3. 0.096146 0.193869 0.496 0.619941
ema_beep_f4:ema_dayEMA 3. 0.133786 0.196860 0.680 0.496759
ema_beep_f5:ema_dayEMA 3. 0.042645 0.200721 0.212 0.831750
ema_beep_f6:ema_dayEMA 3. 0.236219 0.187347 1.261 0.207359
ema_beep_f2:ema_dayEMA 4. -0.022167 0.197253 -0.112 0.910522
ema_beep_f3:ema_dayEMA 4. 0.056756 0.196593 0.289 0.772813
ema_beep_f4:ema_dayEMA 4. -0.149687 0.197554 -0.758 0.448628
ema_beep_f5:ema_dayEMA 4. -0.056416 0.200066 -0.282 0.777953
ema_beep_f6:ema_dayEMA 4. 0.148919 0.188120 0.792 0.428586
ema_beep_f2:ema_dayEMA 5. 0.281035 0.190467 1.476 0.140076
ema_beep_f3:ema_dayEMA 5. 0.319475 0.192048 1.664 0.096210 .
ema_beep_f4:ema_dayEMA 5. 0.106318 0.192755 0.552 0.581243
ema_beep_f5:ema_dayEMA 5. 0.161619 0.201315 0.803 0.422083
ema_beep_f6:ema_dayEMA 5. 0.269338 0.183977 1.464 0.143200
ema_beep_f2:ema_dayEMA 6. 0.038573 0.195616 0.197 0.843683
ema_beep_f3:ema_dayEMA 6. 0.058879 0.195879 0.301 0.763729
ema_beep_f4:ema_dayEMA 6. -0.036330 0.199439 -0.182 0.855456
ema_beep_f5:ema_dayEMA 6. -0.209064 0.204663 -1.022 0.307017
ema_beep_f6:ema_dayEMA 6. 0.044939 0.191264 0.235 0.814240
ema_beep_f2:ema_dayEMA 7. 0.043551 0.200070 0.218 0.827681
ema_beep_f3:ema_dayEMA 7. 0.115001 0.197599 0.582 0.560572
ema_beep_f4:ema_dayEMA 7. -0.122129 0.203205 -0.601 0.547830
ema_beep_f5:ema_dayEMA 7. -0.084735 0.203495 -0.416 0.677118
ema_beep_f6:ema_dayEMA 7. 0.342276 0.212607 1.610 0.107420
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.hr_min_week <- glmer( hr_min_s ~ Week_Type +
Sex + Program + # Model pop differences
First_Week + ema_beep_f*ema_day + # Model day related differencxes
physical_excercise_dur +acc_delta + # Modle movement stuff
temp_mean_z + temp_slope_z + # Model temp effects
(1+Week_Type |castor_record_id) +
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id) +
(0+physical_excercise_dur|castor_record_id) + (0+acc_delta|castor_record_id) +
(1 | castor_record_id:ema_day:ema_beep_f),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.hr_min_week)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: hr_min_s ~ Week_Type + Sex + Program + First_Week + ema_beep_f * ema_day + physical_excercise_dur + acc_delta + temp_mean_z +
temp_slope_z + (1 + Week_Type | castor_record_id) + (0 + temp_slope_z | castor_record_id) + (0 + temp_mean_z | castor_record_id) +
(0 + physical_excercise_dur | castor_record_id) + (0 + acc_delta | castor_record_id) + (1 | castor_record_id:ema_day:ema_beep_f)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
9628.6 10009.6 -4755.3 9510.6 4652
Scaled residuals:
Min 1Q Median 3Q Max
-3.1208 -0.5161 -0.0216 0.4919 6.4178
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id.ema_day.ema_beep_f (Intercept) 0.2552349 0.50521
castor_record_id acc_delta 0.0006928 0.02632
castor_record_id.1 physical_excercise_dur 0.2348128 0.48457
castor_record_id.2 temp_mean_z 0.0245331 0.15663
castor_record_id.3 temp_slope_z 0.0264318 0.16258
castor_record_id.4 (Intercept) 0.0859233 0.29313
Week_TypeStress 0.0589009 0.24270 -0.42
Residual 0.0280606 0.16751
Number of obs: 4711, groups: castor_record_id:ema_day:ema_beep_f, 2958; castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 3.809929 0.113571 33.547 < 2e-16 ***
Week_TypeStress -0.024566 0.033728 -0.728 0.46638
SexMale -0.330923 0.071350 -4.638 3.52e-06 ***
ProgramBSc_Med 0.035281 0.077996 0.452 0.65103
First_WeekExam-First 0.088413 0.073143 1.209 0.22675
ema_beep_f2 -0.057447 0.119076 -0.482 0.62949
ema_beep_f3 -0.062725 0.118461 -0.529 0.59646
ema_beep_f4 0.122668 0.120279 1.020 0.30779
ema_beep_f5 -0.029771 0.125545 -0.237 0.81255
ema_beep_f6 -0.286848 0.117785 -2.435 0.01488 *
ema_dayEMA 2. -0.036492 0.118655 -0.308 0.75843
ema_dayEMA 3. -0.038427 0.122204 -0.314 0.75318
ema_dayEMA 4. -0.129207 0.120995 -1.068 0.28558
ema_dayEMA 5. -0.015433 0.119295 -0.129 0.89707
ema_dayEMA 6. 0.091826 0.124785 0.736 0.46181
ema_dayEMA 7. -0.168629 0.122494 -1.377 0.16863
physical_excercise_dur 0.535729 0.101994 5.253 1.50e-07 ***
acc_delta 0.090369 0.004400 20.541 < 2e-16 ***
temp_mean_z 0.076989 0.024356 3.161 0.00157 **
temp_slope_z 0.038310 0.025882 1.480 0.13882
ema_beep_f2:ema_dayEMA 2. 0.105223 0.167068 0.630 0.52881
ema_beep_f3:ema_dayEMA 2. 0.034657 0.167848 0.206 0.83642
ema_beep_f4:ema_dayEMA 2. 0.057317 0.170240 0.337 0.73636
ema_beep_f5:ema_dayEMA 2. 0.031300 0.171108 0.183 0.85485
ema_beep_f6:ema_dayEMA 2. 0.045726 0.164290 0.278 0.78076
ema_beep_f2:ema_dayEMA 3. 0.081462 0.171153 0.476 0.63410
ema_beep_f3:ema_dayEMA 3. 0.002299 0.169145 0.014 0.98915
ema_beep_f4:ema_dayEMA 3. -0.054146 0.171183 -0.316 0.75177
ema_beep_f5:ema_dayEMA 3. 0.048431 0.175802 0.275 0.78294
ema_beep_f6:ema_dayEMA 3. -0.026465 0.165922 -0.160 0.87327
ema_beep_f2:ema_dayEMA 4. 0.077673 0.170613 0.455 0.64892
ema_beep_f3:ema_dayEMA 4. 0.052666 0.169281 0.311 0.75571
ema_beep_f4:ema_dayEMA 4. 0.037419 0.171221 0.219 0.82701
ema_beep_f5:ema_dayEMA 4. 0.252003 0.174334 1.446 0.14831
ema_beep_f6:ema_dayEMA 4. 0.126668 0.165737 0.764 0.44471
ema_beep_f2:ema_dayEMA 5. 0.001942 0.166537 0.012 0.99070
ema_beep_f3:ema_dayEMA 5. 0.020570 0.167875 0.123 0.90248
ema_beep_f4:ema_dayEMA 5. -0.167078 0.169147 -0.988 0.32327
ema_beep_f5:ema_dayEMA 5. -0.010888 0.176530 -0.062 0.95082
ema_beep_f6:ema_dayEMA 5. -0.045625 0.164892 -0.277 0.78201
ema_beep_f2:ema_dayEMA 6. 0.037415 0.171167 0.219 0.82697
ema_beep_f3:ema_dayEMA 6. -0.035933 0.170648 -0.211 0.83322
ema_beep_f4:ema_dayEMA 6. -0.173388 0.174050 -0.996 0.31916
ema_beep_f5:ema_dayEMA 6. -0.190617 0.179189 -1.064 0.28743
ema_beep_f6:ema_dayEMA 6. -0.229110 0.170065 -1.347 0.17792
ema_beep_f2:ema_dayEMA 7. 0.175024 0.171736 1.019 0.30813
ema_beep_f3:ema_dayEMA 7. 0.154267 0.169720 0.909 0.36338
ema_beep_f4:ema_dayEMA 7. 0.045564 0.175439 0.260 0.79509
ema_beep_f5:ema_dayEMA 7. 0.121611 0.175545 0.693 0.48846
ema_beep_f6:ema_dayEMA 7. 0.377271 0.186892 2.019 0.04352 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 50 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
tab_model(glmer.hr_mean_week, glmer.hr_min_week, glmer.hr_max_week, glmer.hr_sd_week,
terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
dv.labels=c("Mean", "Min", "Max", "SD"),
title="Table 3. HR vs Week Type", #p.adjust = "fdr",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Mean | Min | Max | SD | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 3.26 | 0.09 | 3.08 – 3.44 | 35.51 | <0.001 | 3.81 | 0.11 | 3.59 – 4.03 | 33.55 | <0.001 | 3.61 | 0.12 | 3.38 – 3.84 | 30.69 | <0.001 | 0.80 | 0.05 | 0.70 – 0.89 | 16.52 | <0.001 |
| Week_Type [Stress] | -0.06 | 0.03 | -0.11 – -0.00 | -2.10 | 0.035 | -0.02 | 0.03 | -0.09 – 0.04 | -0.73 | 0.466 | -0.10 | 0.03 | -0.17 – -0.04 | -3.18 | 0.001 | -0.02 | 0.01 | -0.05 – 0.00 | -1.63 | 0.102 |
| Sex [Male] | -0.05 | 0.06 | -0.17 – 0.06 | -0.91 | 0.360 | -0.33 | 0.07 | -0.47 – -0.19 | -4.64 | <0.001 | 0.09 | 0.06 | -0.03 – 0.21 | 1.50 | 0.134 | 0.13 | 0.03 | 0.08 – 0.18 | 5.13 | <0.001 |
| Program [BSc_Med] | 0.13 | 0.06 | 0.01 – 0.26 | 2.10 | 0.036 | 0.04 | 0.08 | -0.12 – 0.19 | 0.45 | 0.651 | 0.07 | 0.06 | -0.06 – 0.20 | 1.08 | 0.278 | 0.01 | 0.03 | -0.04 – 0.07 | 0.48 | 0.628 |
| First_Week [Exam-First] | 0.12 | 0.06 | 0.00 – 0.23 | 1.97 | 0.048 | 0.09 | 0.07 | -0.05 – 0.23 | 1.21 | 0.227 | 0.11 | 0.06 | -0.01 – 0.23 | 1.83 | 0.067 | 0.04 | 0.03 | -0.01 – 0.09 | 1.54 | 0.123 |
| physical_excercise_dur | 0.50 | 0.08 | 0.34 – 0.67 | 6.03 | <0.001 | 0.54 | 0.10 | 0.34 – 0.74 | 5.25 | <0.001 | 0.43 | 0.11 | 0.20 – 0.65 | 3.76 | <0.001 | 0.03 | 0.05 | -0.07 – 0.13 | 0.62 | 0.533 |
| acc_delta | 0.13 | 0.00 | 0.12 – 0.14 | 29.45 | <0.001 | 0.09 | 0.00 | 0.08 – 0.10 | 20.54 | <0.001 | 0.16 | 0.01 | 0.15 – 0.17 | 28.60 | <0.001 | 0.04 | 0.00 | 0.04 – 0.04 | 21.16 | <0.001 |
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||
| 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | |||||||||||||||||
| 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | |||||||||||||||||
| Observations | 4711 | 4711 | 4711 | 4711 | ||||||||||||||||
I will now make a table for all physiology measures.These tables will also have the FDR adjusted values that we report in our article.
tab_model(glmer.sc_ton_mean_week, glmer.sc_ph_num, glmer.sc_ph_mag, glmer.sc_ph_auc_week, glmer.hr_mean_week, glmer.hr_min_week, glmer.hr_max_week,
terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur",
"temp_mean_z", "temp_slope_z"),
dv.labels=c("SC Tonic", "SC Number", "SC Magnitude", "SC AUC", "HR Mean", "HR Min", "HR Max"),
title="Table 3. Physio vs Week Type",
transform=NULL, p.adjust="fdr",
show.stat=TRUE,
show.se=T) %>%
return() %$%
knitr %>%
asis_output()
| SC Tonic | SC Number | SC Magnitude | SC AUC | HR Mean | HR Min | HR Max | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Log-Mean | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.10 | 0.03 | 0.05 – 0.16 | 3.70 | 0.005 | 1.52 | 0.30 | 0.94 – 2.10 | 5.14 | <0.001 | 2.09 | 0.12 | 1.87 – 2.32 | 18.17 | <0.001 | 0.39 | 0.06 | 0.27 – 0.51 | 6.37 | <0.001 | 3.26 | 0.09 | 3.08 – 3.44 | 35.51 | <0.001 | 3.81 | 0.11 | 3.59 – 4.03 | 33.55 | <0.001 | 3.61 | 0.12 | 3.38 – 3.84 | 30.69 | <0.001 |
| Week_Type [Stress] | -0.01 | 0.01 | -0.03 – 0.01 | -0.76 | 0.963 | -0.28 | 0.08 | -0.43 – -0.12 | -3.50 | 0.006 | -0.07 | 0.04 | -0.15 – 0.01 | -1.76 | 0.641 | -0.06 | 0.02 | -0.10 – -0.02 | -2.91 | 0.036 | -0.06 | 0.03 | -0.11 – -0.00 | -2.10 | 0.299 | -0.02 | 0.03 | -0.09 – 0.04 | -0.73 | 0.960 | -0.10 | 0.03 | -0.17 – -0.04 | -3.18 | 0.012 |
| Sex [Male] | 0.00 | 0.01 | -0.02 – 0.03 | 0.04 | 0.982 | 0.41 | 0.25 | -0.07 – 0.89 | 1.68 | 0.312 | 0.10 | 0.06 | -0.02 – 0.21 | 1.62 | 0.641 | 0.01 | 0.03 | -0.05 – 0.08 | 0.36 | 0.851 | -0.05 | 0.06 | -0.17 – 0.06 | -0.91 | 0.999 | -0.33 | 0.07 | -0.47 – -0.19 | -4.64 | <0.001 | 0.09 | 0.06 | -0.03 – 0.21 | 1.50 | 0.551 |
| First_Week [Exam-First] | -0.04 | 0.01 | -0.06 – -0.01 | -2.83 | 0.050 | 0.04 | 0.25 | -0.46 – 0.53 | 0.14 | 0.966 | -0.01 | 0.06 | -0.13 – 0.11 | -0.20 | 0.981 | -0.03 | 0.03 | -0.10 – 0.03 | -1.01 | 0.556 | 0.12 | 0.06 | 0.00 – 0.23 | 1.97 | 0.310 | 0.09 | 0.07 | -0.05 – 0.23 | 1.21 | 0.898 | 0.11 | 0.06 | -0.01 – 0.23 | 1.83 | 0.420 |
| physical_excercise_dur | 0.06 | 0.03 | -0.01 – 0.12 | 1.79 | 0.461 | 0.07 | 0.32 | -0.56 – 0.70 | 0.20 | 0.931 | 0.25 | 0.11 | 0.04 – 0.47 | 2.31 | 0.210 | 0.07 | 0.06 | -0.05 – 0.18 | 1.16 | 0.488 | 0.50 | 0.08 | 0.34 – 0.67 | 6.03 | <0.001 | 0.54 | 0.10 | 0.34 – 0.74 | 5.25 | <0.001 | 0.43 | 0.11 | 0.20 – 0.65 | 3.76 | 0.002 |
| acc_delta | 0.01 | 0.00 | 0.01 – 0.02 | 9.93 | <0.001 | 0.15 | 0.01 | 0.12 – 0.17 | 10.79 | <0.001 | 0.10 | 0.01 | 0.09 – 0.11 | 20.26 | <0.001 | 0.04 | 0.00 | 0.03 – 0.04 | 15.77 | <0.001 | 0.13 | 0.00 | 0.12 – 0.14 | 29.45 | <0.001 | 0.09 | 0.00 | 0.08 – 0.10 | 20.54 | <0.001 | 0.16 | 0.01 | 0.15 – 0.17 | 28.60 | <0.001 |
| temp_mean_z | 0.02 | 0.01 | 0.01 – 0.03 | 3.15 | 0.028 | 0.32 | 0.07 | 0.18 – 0.45 | 4.61 | <0.001 | 0.08 | 0.02 | 0.04 – 0.13 | 3.59 | 0.005 | 0.07 | 0.01 | 0.04 – 0.09 | 4.89 | <0.001 | -0.04 | 0.02 | -0.09 – -0.00 | -1.96 | 0.310 | 0.08 | 0.02 | 0.03 – 0.12 | 3.16 | 0.016 | -0.17 | 0.03 | -0.23 – -0.12 | -6.36 | <0.001 |
| temp_slope_z | 0.02 | 0.01 | 0.01 – 0.04 | 2.81 | 0.050 | 0.19 | 0.06 | 0.08 – 0.30 | 3.43 | 0.006 | 0.07 | 0.02 | 0.03 – 0.12 | 3.20 | 0.017 | 0.04 | 0.01 | 0.02 – 0.07 | 3.20 | 0.017 | 0.03 | 0.02 | -0.01 – 0.08 | 1.60 | 0.606 | 0.04 | 0.03 | -0.01 – 0.09 | 1.48 | 0.809 | 0.03 | 0.03 | -0.02 – 0.08 | 1.04 | 0.853 |
| Program [BSc_Med] | 0.13 | 0.27 | -0.40 – 0.66 | 0.49 | 0.825 | -0.01 | 0.07 | -0.13 – 0.12 | -0.08 | 0.988 | 0.01 | 0.04 | -0.06 – 0.09 | 0.39 | 0.851 | 0.13 | 0.06 | 0.01 – 0.26 | 2.10 | 0.299 | 0.04 | 0.08 | -0.12 – 0.19 | 0.45 | 0.960 | 0.07 | 0.06 | -0.06 – 0.20 | 1.08 | 0.853 | |||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||||||||||||||
| 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | 7 ema_day | |||||||||||||||||||||||||||||
| 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | 6 ema_beep_f | |||||||||||||||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | 4711 | 4711 | 4711 | ||||||||||||||||||||||||||||
And now I also plot the figure we use in the article with all the outcome measures including the affect items. I again do FDR correction here.
# Together
plot.physio <- plot_models(glmer.posmood_week, glmer.sc_ton_mean_week, glmer.sc_ph_num)
rm_term <- as.vector(plot.physio$data$term[1:97])
rm_term <- rm_term[rm_term != "Week_TypeStress"]
# Color list
col_list <-c('#7570B3','#7570B3','#7570B3',"#D95F02", "#D95F02", '#D95F02', '#D95F02', "#1B9E77", "#1B9E77")
# Make the plot
plot.all_week_resid <- plot_models( glmer.posmood_week, glmer.negmood_week,
glmer.sc_ton_mean_week, glmer.sc_ph_num, glmer.sc_ph_mag, glmer.sc_ph_auc_week,
glmer.hr_mean_week, glmer.hr_min_week, glmer.hr_max_week,
m.labels=c("Positive Affect", "Negative Affect", "SC Tonic", "SC Number", "SC Magnitued", "SC AUC","HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(" "),
# Stastistical Stuff
rm.terms = rm_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size = 1,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme +
theme(axis.ticks.y=element_blank(),
legend.text=element_text(size=16), legend.title = element_text(size=16),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
# Plot and save
plot.all_week_resid + coord_flip(ylim=c(-0.5,0.5)) + theme(panel.grid.major.y = element_line(colour = "grey95"), panel.grid.minor.y = element_line(colour = "grey90"))
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_WeekResid_ALL.tiff", units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
So overall all, our first analysis confirms that our stress week results in increased stress. This has a direct consequence on mood outcomes, and physiology. But the physiology is not really in the expected direction which is a bit strange. Interestingly though, the physiology is in the same direction as positive affect. So this indicated to me maybe that we are looking at reductions in positive arousal.
Now we found week differences in both the EMA and EPA measures, the next step will be to investigate the relaitonship between subjective stress as and our outcome measures on a beep to beep level. This is a bit of a replicaiton attempt of previous studies, where we also try to explain the previous findings. Is it linked to positive affect as well?
For these models, we know that activity stress is correlated with event and social stress, which we present below. So to adjust for that, we also model interaction terms for these variables specifically. We model similar covariates, but not day here, only time of day since we arent looking at the weeks in a linear fashion. Due to convergence issues with the maximal models, we have a fixed intercept for our fixed effects of interest in these models.
rcorr(as.matrix(EMA_Data[,c("event_tot_s", "activity_tot_s", "social_tot_s", "physical_tot_s")]))
event_tot_s activity_tot_s social_tot_s physical_tot_s
event_tot_s 1.00 0.42 0.17 0.07
activity_tot_s 0.42 1.00 0.34 0.15
social_tot_s 0.17 0.34 1.00 0.18
physical_tot_s 0.07 0.15 0.18 1.00
n
event_tot_s activity_tot_s social_tot_s physical_tot_s
event_tot_s 6160 6153 6160 6146
activity_tot_s 6153 6153 6153 6146
social_tot_s 6160 6153 6623 6146
physical_tot_s 6146 6146 6146 6146
P
event_tot_s activity_tot_s social_tot_s physical_tot_s
event_tot_s 0 0 0
activity_tot_s 0 0 0
social_tot_s 0 0 0
physical_tot_s 0 0 0
First we take a look at the affect/mood items.We use the maximal fitting with all the families and links, and pick the best fit for our results.
glmer.posmood_beep <- glmer(mood_positive_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=gaussian(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
# Summary
summary(glmer.posmood_beep )
Linear mixed model fit by REML ['lmerMod']
Formula: mood_positive_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
REML criterion at convergence: 15728.4
Scaled residuals:
Min 1Q Median 3Q Max
-6.0466 -0.5682 0.0480 0.6304 3.7752
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.016084 0.12682
activity_tot_s 0.005431 0.07369 -0.23
social_tot_s 0.012216 0.11053 -0.30 0.18
physical_tot_s 0.017675 0.13295 -0.16 -0.45 -0.15
castor_record_id.1 ema_beep 0.004990 0.07064
castor_record_id.2 temp_slope_z 0.000000 0.00000
castor_record_id.3 temp_mean_z 0.017711 0.13308
castor_record_id.4 acc_delta 0.000000 0.00000
castor_record_id.5 physical_excercise_dur 0.220847 0.46994
Residual 1.120788 1.05867
Number of obs: 5109, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 9.735980 0.198727 48.992
event_tot_s -0.125210 0.033495 -3.738
activity_tot_s -0.201643 0.039304 -5.130
social_tot_s -0.295075 0.030157 -9.785
physical_tot_s -0.152168 0.019395 -7.846
ema_beep -0.011329 0.012413 -0.913
SexMale 0.262580 0.139864 1.877
physical_excercise_dur 0.566937 0.122851 4.615
acc_delta 0.004665 0.003012 1.549
temp_mean_z -0.002554 0.025937 -0.098
temp_slope_z -0.012033 0.015551 -0.774
event_tot_s:activity_tot_s -0.016230 0.005886 -2.757
activity_tot_s:social_tot_s 0.025817 0.005103 5.059
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
glmer.negmood_beep <- glmer(mood_negative_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.negmood_beep)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: mood_negative_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
12654.5 12844.1 -6298.2 12596.5 5080
Scaled residuals:
Min 1Q Median 3Q Max
-1.9947 -0.5958 -0.1358 0.4195 8.3307
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.0034002 0.05831
activity_tot_s 0.0041612 0.06451 -0.16
social_tot_s 0.0091417 0.09561 -0.19 0.01
physical_tot_s 0.0093120 0.09650 -0.17 0.08 -0.24
castor_record_id.1 ema_beep 0.0031490 0.05612
castor_record_id.2 temp_slope_z 0.0026964 0.05193
castor_record_id.3 temp_mean_z 0.0230049 0.15167
castor_record_id.4 acc_delta 0.0001234 0.01111
castor_record_id.5 physical_excercise_dur 0.0624166 0.24983
Residual 0.1446789 0.38037
Number of obs: 5109, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.775096 0.131616 5.889 3.88e-09 ***
event_tot_s 0.038533 0.020887 1.845 0.0651 .
activity_tot_s 0.088208 0.028408 3.105 0.0019 **
social_tot_s 0.233902 0.022812 10.254 < 2e-16 ***
physical_tot_s 0.119440 0.014848 8.044 8.68e-16 ***
ema_beep 0.020597 0.009765 2.109 0.0349 *
SexMale -0.219085 0.095448 -2.295 0.0217 *
physical_excercise_dur -0.188981 0.077739 -2.431 0.0151 *
acc_delta -0.002205 0.002731 -0.807 0.4195
temp_mean_z 0.019316 0.024513 0.788 0.4307
temp_slope_z -0.011289 0.014402 -0.784 0.4331
event_tot_s:activity_tot_s 0.010379 0.004196 2.473 0.0134 *
activity_tot_s:social_tot_s -0.011324 0.003854 -2.938 0.0033 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
Now I can present a table of nelow to make it a little prettier.
tab_model(glmer.posmood_beep, glmer.negmood_beep,
# terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
title="Table 3. HR vs Week Type",
transform=NULL, p.adjust = "fdr",
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| mood positive s | mood negative s | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 9.74 | 0.20 | 9.35 – 10.13 | 48.99 | <0.001 | 0.78 | 0.13 | 0.52 – 1.03 | 5.89 | <0.001 |
| event_tot_s | -0.13 | 0.03 | -0.19 – -0.06 | -3.74 | <0.001 | 0.04 | 0.02 | -0.00 – 0.08 | 1.84 | 0.085 |
| activity_tot_s | -0.20 | 0.04 | -0.28 – -0.12 | -5.13 | <0.001 | 0.09 | 0.03 | 0.03 – 0.14 | 3.11 | 0.006 |
| social_tot_s | -0.30 | 0.03 | -0.35 – -0.24 | -9.78 | <0.001 | 0.23 | 0.02 | 0.19 – 0.28 | 10.25 | <0.001 |
| physical_tot_s | -0.15 | 0.02 | -0.19 – -0.11 | -7.85 | <0.001 | 0.12 | 0.01 | 0.09 – 0.15 | 8.04 | <0.001 |
| ema_beep | -0.01 | 0.01 | -0.04 – 0.01 | -0.91 | 0.427 | 0.02 | 0.01 | 0.00 – 0.04 | 2.11 | 0.050 |
| Sex [Male] | 0.26 | 0.14 | -0.01 – 0.54 | 1.88 | 0.087 | -0.22 | 0.10 | -0.41 – -0.03 | -2.30 | 0.035 |
| physical_excercise_dur | 0.57 | 0.12 | 0.33 – 0.81 | 4.61 | <0.001 | -0.19 | 0.08 | -0.34 – -0.04 | -2.43 | 0.028 |
| acc_delta | 0.00 | 0.00 | -0.00 – 0.01 | 1.55 | 0.158 | -0.00 | 0.00 | -0.01 – 0.00 | -0.81 | 0.433 |
| temp_mean_z | -0.00 | 0.03 | -0.05 – 0.05 | -0.10 | 0.922 | 0.02 | 0.02 | -0.03 – 0.07 | 0.79 | 0.433 |
| temp_slope_z | -0.01 | 0.02 | -0.04 – 0.02 | -0.77 | 0.476 | -0.01 | 0.01 | -0.04 – 0.02 | -0.78 | 0.433 |
|
event_tot_s * activity_tot_s |
-0.02 | 0.01 | -0.03 – -0.00 | -2.76 | 0.009 | 0.01 | 0.00 | 0.00 – 0.02 | 2.47 | 0.028 |
|
activity_tot_s * social_tot_s |
0.03 | 0.01 | 0.02 – 0.04 | 5.06 | <0.001 | -0.01 | 0.00 | -0.02 – -0.00 | -2.94 | 0.009 |
| Random Effects | ||||||||||
| σ2 | 1.12 | 0.14 | ||||||||
| τ00 | 0.02 castor_record_id | 0.00 castor_record_id | ||||||||
| 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||
| 0.00 castor_record_id.2 | 0.00 castor_record_id.2 | |||||||||
| 0.02 castor_record_id.3 | 0.02 castor_record_id.3 | |||||||||
| 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||
| 0.22 castor_record_id.5 | 0.06 castor_record_id.5 | |||||||||
| τ11 | 0.01 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | ||||||||
| 0.01 castor_record_id.social_tot_s | 0.01 castor_record_id.social_tot_s | |||||||||
| 0.02 castor_record_id.physical_tot_s | 0.01 castor_record_id.physical_tot_s | |||||||||
| ρ01 | -0.23 castor_record_id.activity_tot_s | -0.16 castor_record_id.activity_tot_s | ||||||||
| -0.30 castor_record_id.social_tot_s | -0.19 castor_record_id.social_tot_s | |||||||||
| -0.16 castor_record_id.physical_tot_s | -0.17 castor_record_id.physical_tot_s | |||||||||
| ICC | 0.74 | |||||||||
| N | 82 castor_record_id | 82 castor_record_id | ||||||||
| Observations | 5109 | 5109 | ||||||||
| Marginal R2 / Conditional R2 | 0.352 / NA | 0.343 / 0.826 | ||||||||
Next we will also chekc the skin conductance measures for the moment-to-moment effects. Perhaps in the weeks the physiology measures arent increased, but in moments of stress they are. We again fit the models with different families and links, and pick the best fit which is presented here.
# Model
glmer.sc_ton_ema <- glmer(sc_tonic_mean_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
failure to converge in 10000 evaluations
# Summary
summary(glmer.sc_ton_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: sc_tonic_mean_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
748.9 937.1 -345.4 690.9 4842
Scaled residuals:
Min 1Q Median 3Q Max
-2.1970 -0.3354 -0.1286 0.0539 17.6415
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.0005510 0.02347
activity_tot_s 0.0004086 0.02021 -0.51
social_tot_s 0.0005522 0.02350 -0.61 -0.07
physical_tot_s 0.0005224 0.02286 -0.53 0.06 -0.03
castor_record_id.1 ema_beep 0.0002210 0.01487
castor_record_id.2 temp_slope_z 0.0036368 0.06031
castor_record_id.3 temp_mean_z 0.0038344 0.06192
castor_record_id.4 acc_delta 0.0001957 0.01399
castor_record_id.5 physical_excercise_dur 0.0615310 0.24805
Residual 0.0794423 0.28186
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.0157222 0.0531383 0.296 0.7673
event_tot_s 0.0088944 0.0086382 1.030 0.3032
activity_tot_s 0.0080807 0.0106621 0.758 0.4485
social_tot_s 0.0038961 0.0079498 0.490 0.6241
physical_tot_s -0.0035858 0.0041620 -0.862 0.3889
ema_beep 0.0017615 0.0031239 0.564 0.5728
SexMale -0.0007394 0.0192677 -0.038 0.9694
physical_excercise_dur 0.0562354 0.0439188 1.280 0.2004
acc_delta 0.0175983 0.0018703 9.409 < 2e-16 ***
temp_mean_z 0.0404021 0.0090850 4.447 8.7e-06 ***
temp_slope_z 0.0256005 0.0092021 2.782 0.0054 **
event_tot_s:activity_tot_s -0.0015035 0.0015904 -0.945 0.3445
activity_tot_s:social_tot_s -0.0010889 0.0013955 -0.780 0.4352
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
convergence code: 0
failure to converge in 10000 evaluations
# Model
glmer.sc_ph_num_ema <- glmer(sc_phasic_num ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=poisson(link="sqrt"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.sc_ph_num_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( sqrt )
Formula: sc_phasic_num ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
80922.0 81103.8 -40433.0 80866.0 4843
Scaled residuals:
Min 1Q Median 3Q Max
-8.4026 -2.4665 -0.9137 1.6154 19.5023
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.04349 0.2085
activity_tot_s 0.06333 0.2517 -0.24
social_tot_s 0.04885 0.2210 -0.11 -0.51
physical_tot_s 0.06791 0.2606 -0.28 -0.22 -0.05
castor_record_id.1 ema_beep 0.04248 0.2061
castor_record_id.2 temp_slope_z 0.39586 0.6292
castor_record_id.3 temp_mean_z 0.67538 0.8218
castor_record_id.4 acc_delta 0.01429 0.1195
castor_record_id.5 physical_excercise_dur 11.02768 3.3208
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.102315 0.109044 19.279 < 2e-16 ***
event_tot_s 0.043802 0.028265 1.550 0.121223
activity_tot_s 0.061466 0.034576 1.778 0.075456 .
social_tot_s 0.010763 0.028890 0.373 0.709496
physical_tot_s 0.017852 0.029628 0.603 0.546822
ema_beep -0.049380 0.023363 -2.114 0.034548 *
SexMale 0.833191 0.110835 7.517 5.59e-14 ***
physical_excercise_dur -0.060419 0.384936 -0.157 0.875277
acc_delta 0.223370 0.013428 16.635 < 2e-16 ***
temp_mean_z 0.445457 0.091961 4.844 1.27e-06 ***
temp_slope_z 0.245012 0.070945 3.454 0.000553 ***
event_tot_s:activity_tot_s -0.007416 0.003124 -2.374 0.017597 *
activity_tot_s:social_tot_s -0.008608 0.002812 -3.061 0.002204 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.sc_ph_mag_ema <- glmer(sc_phasic_mag_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.sc_ph_mag_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: sc_phasic_mag_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
11928.1 12116.3 -5935.1 11870.1 4842
Scaled residuals:
Min 1Q Median 3Q Max
-1.8549 -0.6145 -0.1341 0.4453 8.7917
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.003719 0.06098
activity_tot_s 0.002491 0.04991 -0.43
social_tot_s 0.002295 0.04791 -0.42 -0.16
physical_tot_s 0.004252 0.06521 -0.30 -0.14 -0.12
castor_record_id.1 ema_beep 0.001755 0.04190
castor_record_id.2 temp_slope_z 0.010261 0.10130
castor_record_id.3 temp_mean_z 0.025211 0.15878
castor_record_id.4 acc_delta 0.001430 0.03782
castor_record_id.5 physical_excercise_dur 0.370433 0.60863
Residual 0.166489 0.40803
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.410041 0.159517 8.839 < 2e-16 ***
event_tot_s 0.070813 0.025461 2.781 0.005415 **
activity_tot_s 0.051720 0.031480 1.643 0.100388
social_tot_s -0.017789 0.022770 -0.781 0.434662
physical_tot_s 0.027130 0.012434 2.182 0.029113 *
ema_beep -0.002391 0.009127 -0.262 0.793329
SexMale 0.039797 0.071330 0.558 0.576899
physical_excercise_dur 0.352150 0.122616 2.872 0.004079 **
acc_delta 0.108003 0.005845 18.477 < 2e-16 ***
temp_mean_z 0.122658 0.025015 4.903 9.42e-07 ***
temp_slope_z 0.074566 0.021648 3.444 0.000572 ***
event_tot_s:activity_tot_s -0.011383 0.004692 -2.426 0.015264 *
activity_tot_s:social_tot_s 0.001372 0.004097 0.335 0.737664
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.sc_ph_auc_ema <- glmer(sc_phasic_auc_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.sc_ph_auc_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: sc_phasic_auc_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
10457.8 10646.1 -5199.9 10399.8 4842
Scaled residuals:
Min 1Q Median 3Q Max
-1.6507 -0.5402 -0.2507 0.1555 7.4885
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.001267 0.03560
activity_tot_s 0.002063 0.04542 -0.04
social_tot_s 0.002549 0.05049 -0.59 -0.36
physical_tot_s 0.002410 0.04909 -0.31 -0.44 0.10
castor_record_id.1 ema_beep 0.001842 0.04291
castor_record_id.2 temp_slope_z 0.016889 0.12996
castor_record_id.3 temp_mean_z 0.026906 0.16403
castor_record_id.4 acc_delta 0.002694 0.05190
castor_record_id.5 physical_excercise_dur 0.185929 0.43119
Residual 0.252030 0.50203
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.075483 0.152345 7.060 1.67e-12 ***
event_tot_s 0.023499 0.023533 0.999 0.318005
activity_tot_s 0.025375 0.029865 0.850 0.395517
social_tot_s 0.002950 0.021879 0.135 0.892744
physical_tot_s 0.008871 0.010921 0.812 0.416642
ema_beep 0.011422 0.008897 1.284 0.199225
SexMale 0.045296 0.062609 0.723 0.469387
physical_excercise_dur 0.214040 0.104933 2.040 0.041372 *
acc_delta 0.119242 0.007144 16.691 < 2e-16 ***
temp_mean_z 0.125246 0.024873 5.035 4.77e-07 ***
temp_slope_z 0.088357 0.023585 3.746 0.000179 ***
event_tot_s:activity_tot_s -0.003589 0.004442 -0.808 0.419214
activity_tot_s:social_tot_s -0.002404 0.003897 -0.617 0.537309
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
Now I make a table for the SC measures. I do not use FDR here, as I only do this in the finaly table we present in the artcle
tab_model(glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
# terms=c("(Intercept)","Week_Type [Stress]", "Sex [Male]", "Program [BSc_Med]", "First_Week [Exam-First]", "acc_delta", "physical_excercise_dur"),
title="Table X. SC v Subjective Stress",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| sc tonic mean s | sc phasic num | sc phasic mag s | sc phasic auc s | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Log-Mean | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.02 | 0.05 | -0.09 – 0.12 | 0.30 | 0.767 | 2.10 | 0.11 | 1.89 – 2.32 | 19.28 | <0.001 | 1.41 | 0.16 | 1.10 – 1.72 | 8.84 | <0.001 | 1.08 | 0.15 | 0.78 – 1.37 | 7.06 | <0.001 |
| event_tot_s | 0.01 | 0.01 | -0.01 – 0.03 | 1.03 | 0.303 | 0.04 | 0.03 | -0.01 – 0.10 | 1.55 | 0.121 | 0.07 | 0.03 | 0.02 – 0.12 | 2.78 | 0.005 | 0.02 | 0.02 | -0.02 – 0.07 | 1.00 | 0.318 |
| activity_tot_s | 0.01 | 0.01 | -0.01 – 0.03 | 0.76 | 0.449 | 0.06 | 0.03 | -0.01 – 0.13 | 1.78 | 0.075 | 0.05 | 0.03 | -0.01 – 0.11 | 1.64 | 0.100 | 0.03 | 0.03 | -0.03 – 0.08 | 0.85 | 0.396 |
| social_tot_s | 0.00 | 0.01 | -0.01 – 0.02 | 0.49 | 0.624 | 0.01 | 0.03 | -0.05 – 0.07 | 0.37 | 0.709 | -0.02 | 0.02 | -0.06 – 0.03 | -0.78 | 0.435 | 0.00 | 0.02 | -0.04 – 0.05 | 0.13 | 0.893 |
| physical_tot_s | -0.00 | 0.00 | -0.01 – 0.00 | -0.86 | 0.389 | 0.02 | 0.03 | -0.04 – 0.08 | 0.60 | 0.547 | 0.03 | 0.01 | 0.00 – 0.05 | 2.18 | 0.029 | 0.01 | 0.01 | -0.01 – 0.03 | 0.81 | 0.417 |
| ema_beep | 0.00 | 0.00 | -0.00 – 0.01 | 0.56 | 0.573 | -0.05 | 0.02 | -0.10 – -0.00 | -2.11 | 0.035 | -0.00 | 0.01 | -0.02 – 0.02 | -0.26 | 0.793 | 0.01 | 0.01 | -0.01 – 0.03 | 1.28 | 0.199 |
| Sex [Male] | -0.00 | 0.02 | -0.04 – 0.04 | -0.04 | 0.969 | 0.83 | 0.11 | 0.62 – 1.05 | 7.52 | <0.001 | 0.04 | 0.07 | -0.10 – 0.18 | 0.56 | 0.577 | 0.05 | 0.06 | -0.08 – 0.17 | 0.72 | 0.469 |
| physical_excercise_dur | 0.06 | 0.04 | -0.03 – 0.14 | 1.28 | 0.200 | -0.06 | 0.38 | -0.81 – 0.69 | -0.16 | 0.875 | 0.35 | 0.12 | 0.11 – 0.59 | 2.87 | 0.004 | 0.21 | 0.10 | 0.01 – 0.42 | 2.04 | 0.041 |
| acc_delta | 0.02 | 0.00 | 0.01 – 0.02 | 9.41 | <0.001 | 0.22 | 0.01 | 0.20 – 0.25 | 16.63 | <0.001 | 0.11 | 0.01 | 0.10 – 0.12 | 18.48 | <0.001 | 0.12 | 0.01 | 0.11 – 0.13 | 16.69 | <0.001 |
| temp_mean_z | 0.04 | 0.01 | 0.02 – 0.06 | 4.45 | <0.001 | 0.45 | 0.09 | 0.27 – 0.63 | 4.84 | <0.001 | 0.12 | 0.03 | 0.07 – 0.17 | 4.90 | <0.001 | 0.13 | 0.02 | 0.08 – 0.17 | 5.04 | <0.001 |
| temp_slope_z | 0.03 | 0.01 | 0.01 – 0.04 | 2.78 | 0.005 | 0.25 | 0.07 | 0.11 – 0.38 | 3.45 | 0.001 | 0.07 | 0.02 | 0.03 – 0.12 | 3.44 | 0.001 | 0.09 | 0.02 | 0.04 – 0.13 | 3.75 | <0.001 |
|
event_tot_s * activity_tot_s |
-0.00 | 0.00 | -0.00 – 0.00 | -0.95 | 0.344 | -0.01 | 0.00 | -0.01 – -0.00 | -2.37 | 0.018 | -0.01 | 0.00 | -0.02 – -0.00 | -2.43 | 0.015 | -0.00 | 0.00 | -0.01 – 0.01 | -0.81 | 0.419 |
|
activity_tot_s * social_tot_s |
-0.00 | 0.00 | -0.00 – 0.00 | -0.78 | 0.435 | -0.01 | 0.00 | -0.01 – -0.00 | -3.06 | 0.002 | 0.00 | 0.00 | -0.01 – 0.01 | 0.33 | 0.738 | -0.00 | 0.00 | -0.01 – 0.01 | -0.62 | 0.537 |
| Random Effects | ||||||||||||||||||||
| σ2 | 0.08 | 0.25 | 0.17 | 0.25 | ||||||||||||||||
| τ00 | 0.00 castor_record_id | 0.04 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | ||||||||||||||||
| 0.00 castor_record_id.1 | 0.04 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||||||
| 0.00 castor_record_id.2 | 0.40 castor_record_id.2 | 0.01 castor_record_id.2 | 0.02 castor_record_id.2 | |||||||||||||||||
| 0.00 castor_record_id.3 | 0.68 castor_record_id.3 | 0.03 castor_record_id.3 | 0.03 castor_record_id.3 | |||||||||||||||||
| 0.00 castor_record_id.4 | 0.01 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||||||
| 0.06 castor_record_id.5 | 11.03 castor_record_id.5 | 0.37 castor_record_id.5 | 0.19 castor_record_id.5 | |||||||||||||||||
| τ11 | 0.00 castor_record_id.activity_tot_s | 0.06 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | ||||||||||||||||
| 0.00 castor_record_id.social_tot_s | 0.05 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | |||||||||||||||||
| 0.00 castor_record_id.physical_tot_s | 0.07 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | |||||||||||||||||
| ρ01 | -0.51 castor_record_id.activity_tot_s | -0.24 castor_record_id.activity_tot_s | -0.43 castor_record_id.activity_tot_s | -0.04 castor_record_id.activity_tot_s | ||||||||||||||||
| -0.61 castor_record_id.social_tot_s | -0.11 castor_record_id.social_tot_s | -0.42 castor_record_id.social_tot_s | -0.59 castor_record_id.social_tot_s | |||||||||||||||||
| -0.53 castor_record_id.physical_tot_s | -0.28 castor_record_id.physical_tot_s | -0.30 castor_record_id.physical_tot_s | -0.31 castor_record_id.physical_tot_s | |||||||||||||||||
| ICC | 0.07 | 0.88 | 0.33 | 0.17 | ||||||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | ||||||||||||||||
| Marginal R2 / Conditional R2 | 0.094 / 0.161 | 0.417 / 0.931 | 0.534 / 0.690 | 0.532 / 0.609 | ||||||||||||||||
Finally we can check the heart rate and moment to moment subjective stress. Same goes as before (families and links tests, only optimal shown).
# Model
glmer.hr_mean_ema <- glmer(hr_mean_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=glmerControl(calc.derivs = FALSE) )
# Model Summary
summary(glmer.hr_mean_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: hr_mean_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
8717.0 8904.3 -4329.5 8659.0 4682
Scaled residuals:
Min 1Q Median 3Q Max
-3.4202 -0.6003 -0.0737 0.4953 10.6267
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.002187 0.04677
activity_tot_s 0.001588 0.03984 -0.50
social_tot_s 0.002099 0.04582 -0.16 -0.21
physical_tot_s 0.002676 0.05173 -0.35 0.11 -0.31
castor_record_id.1 ema_beep 0.001510 0.03885
castor_record_id.2 temp_slope_z 0.011105 0.10538
castor_record_id.3 temp_mean_z 0.020745 0.14403
castor_record_id.4 acc_delta 0.001057 0.03252
castor_record_id.5 physical_excercise_dur 0.181223 0.42570
Residual 0.029608 0.17207
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 3.259889 0.115826 28.145 < 2e-16 ***
event_tot_s 0.013262 0.018356 0.723 0.4700
activity_tot_s -0.010007 0.022837 -0.438 0.6612
social_tot_s -0.028652 0.016813 -1.704 0.0884 .
physical_tot_s 0.016316 0.009320 1.751 0.0800 .
ema_beep -0.044789 0.007175 -6.242 4.31e-10 ***
SexMale -0.004925 0.061770 -0.080 0.9365
physical_excercise_dur 0.462712 0.086796 5.331 9.77e-08 ***
acc_delta 0.142871 0.004758 30.030 < 2e-16 ***
temp_mean_z -0.093975 0.021275 -4.417 1.00e-05 ***
temp_slope_z 0.032899 0.019330 1.702 0.0888 .
event_tot_s:activity_tot_s -0.001799 0.003417 -0.526 0.5987
activity_tot_s:social_tot_s 0.004116 0.002982 1.380 0.1675
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.hr_min_ema <- glmer(hr_min_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.hr_min_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: hr_min_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
10945.0 11132.2 -5443.5 10887.0 4682
Scaled residuals:
Min 1Q Median 3Q Max
-3.1763 -0.6460 -0.0478 0.5441 9.3277
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 8.710e-05 0.009333
activity_tot_s 5.750e-05 0.007583 0.51
social_tot_s 1.709e-04 0.013071 0.14 -0.78
physical_tot_s 3.865e-04 0.019659 -0.55 -0.11 -0.27
castor_record_id.1 ema_beep 1.676e-04 0.012948
castor_record_id.2 temp_slope_z 1.106e-03 0.033264
castor_record_id.3 temp_mean_z 2.010e-03 0.044828
castor_record_id.4 acc_delta 4.644e-05 0.006814
castor_record_id.5 physical_excercise_dur 1.694e-02 0.130158
Residual 4.323e-02 0.207909
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.3502304 0.0396461 34.057 < 2e-16 ***
event_tot_s -0.0011512 0.0061120 -0.188 0.850607
activity_tot_s -0.0107717 0.0076745 -1.404 0.160447
social_tot_s -0.0128868 0.0055910 -2.305 0.021171 *
physical_tot_s 0.0028280 0.0033193 0.852 0.394220
ema_beep -0.0118784 0.0024391 -4.870 1.12e-06 ***
SexMale -0.0750942 0.0200708 -3.741 0.000183 ***
physical_excercise_dur 0.1059833 0.0278223 3.809 0.000139 ***
acc_delta 0.0218142 0.0011148 19.568 < 2e-16 ***
temp_mean_z 0.0117941 0.0068140 1.731 0.083477 .
temp_slope_z 0.0096380 0.0061063 1.578 0.114477
event_tot_s:activity_tot_s -0.0001731 0.0011610 -0.149 0.881505
activity_tot_s:social_tot_s 0.0017559 0.0009926 1.769 0.076883 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
# Model
glmer.hr_max_ema <- glmer(hr_max_s ~
event_tot_s*activity_tot_s + activity_tot_s*social_tot_s + physical_tot_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + physical_excercise_dur + acc_delta +
temp_mean_z + temp_slope_z +
(0+event_tot_s+activity_tot_s+social_tot_s+physical_tot_s | castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=lmerControl(calc.derivs = FALSE) )
please use glmerControl() instead of lmerControl()
# Model Summary
summary(glmer.hr_max_ema)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: hr_max_s ~ event_tot_s * activity_tot_s + activity_tot_s * social_tot_s + physical_tot_s + ema_beep + Sex + physical_excercise_dur +
acc_delta + temp_mean_z + temp_slope_z + (0 + event_tot_s + activity_tot_s + social_tot_s + physical_tot_s | castor_record_id) +
(0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: lmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
12054.5 12241.8 -5998.3 11996.5 4682
Scaled residuals:
Min 1Q Median 3Q Max
-3.0029 -0.6366 -0.1348 0.4838 7.5959
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id event_tot_s 0.004771 0.06907
activity_tot_s 0.002638 0.05136 -0.68
social_tot_s 0.004083 0.06390 -0.07 -0.33
physical_tot_s 0.004273 0.06537 -0.67 0.60 -0.50
castor_record_id.1 ema_beep 0.002061 0.04540
castor_record_id.2 temp_slope_z 0.019433 0.13940
castor_record_id.3 temp_mean_z 0.034834 0.18664
castor_record_id.4 acc_delta 0.001353 0.03678
castor_record_id.5 physical_excercise_dur 0.429877 0.65565
Residual 0.048187 0.21951
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 3.3903417 0.1613062 21.018 < 2e-16 ***
event_tot_s 0.0153649 0.0258572 0.594 0.55237
activity_tot_s 0.0270551 0.0319920 0.846 0.39773
social_tot_s -0.0004125 0.0235979 -0.017 0.98605
physical_tot_s 0.0056451 0.0125522 0.450 0.65291
ema_beep -0.0521387 0.0095804 -5.442 5.26e-08 ***
SexMale 0.1540406 0.0672158 2.292 0.02192 *
physical_excercise_dur 0.4189564 0.1277727 3.279 0.00104 **
acc_delta 0.1770121 0.0060781 29.123 < 2e-16 ***
temp_mean_z -0.2266377 0.0284757 -7.959 1.73e-15 ***
temp_slope_z 0.0299362 0.0269722 1.110 0.26705
event_tot_s:activity_tot_s -0.0029616 0.0048020 -0.617 0.53740
activity_tot_s:social_tot_s -0.0007412 0.0042060 -0.176 0.86012
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 13 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
We now make a table for the heart rate measures for easier visualization.
tab_model(glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
dv.labels=c("Mean", "Min", "Max"),
title="Table X. Heart rate vs. Subjective Stress",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Mean | Min | Max | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 3.26 | 0.12 | 3.03 – 3.49 | 28.14 | <0.001 | 1.35 | 0.04 | 1.27 – 1.43 | 34.06 | <0.001 | 3.39 | 0.16 | 3.07 – 3.71 | 21.02 | <0.001 |
| event_tot_s | 0.01 | 0.02 | -0.02 – 0.05 | 0.72 | 0.470 | -0.00 | 0.01 | -0.01 – 0.01 | -0.19 | 0.851 | 0.02 | 0.03 | -0.04 – 0.07 | 0.59 | 0.552 |
| activity_tot_s | -0.01 | 0.02 | -0.05 – 0.03 | -0.44 | 0.661 | -0.01 | 0.01 | -0.03 – 0.00 | -1.40 | 0.160 | 0.03 | 0.03 | -0.04 – 0.09 | 0.85 | 0.398 |
| social_tot_s | -0.03 | 0.02 | -0.06 – 0.00 | -1.70 | 0.088 | -0.01 | 0.01 | -0.02 – -0.00 | -2.30 | 0.021 | -0.00 | 0.02 | -0.05 – 0.05 | -0.02 | 0.986 |
| physical_tot_s | 0.02 | 0.01 | -0.00 – 0.03 | 1.75 | 0.080 | 0.00 | 0.00 | -0.00 – 0.01 | 0.85 | 0.394 | 0.01 | 0.01 | -0.02 – 0.03 | 0.45 | 0.653 |
| ema_beep | -0.04 | 0.01 | -0.06 – -0.03 | -6.24 | <0.001 | -0.01 | 0.00 | -0.02 – -0.01 | -4.87 | <0.001 | -0.05 | 0.01 | -0.07 – -0.03 | -5.44 | <0.001 |
| Sex [Male] | -0.00 | 0.06 | -0.13 – 0.12 | -0.08 | 0.936 | -0.08 | 0.02 | -0.11 – -0.04 | -3.74 | <0.001 | 0.15 | 0.07 | 0.02 – 0.29 | 2.29 | 0.022 |
| physical_excercise_dur | 0.46 | 0.09 | 0.29 – 0.63 | 5.33 | <0.001 | 0.11 | 0.03 | 0.05 – 0.16 | 3.81 | <0.001 | 0.42 | 0.13 | 0.17 – 0.67 | 3.28 | 0.001 |
| acc_delta | 0.14 | 0.00 | 0.13 – 0.15 | 30.03 | <0.001 | 0.02 | 0.00 | 0.02 – 0.02 | 19.57 | <0.001 | 0.18 | 0.01 | 0.17 – 0.19 | 29.12 | <0.001 |
| temp_mean_z | -0.09 | 0.02 | -0.14 – -0.05 | -4.42 | <0.001 | 0.01 | 0.01 | -0.00 – 0.03 | 1.73 | 0.083 | -0.23 | 0.03 | -0.28 – -0.17 | -7.96 | <0.001 |
| temp_slope_z | 0.03 | 0.02 | -0.00 – 0.07 | 1.70 | 0.089 | 0.01 | 0.01 | -0.00 – 0.02 | 1.58 | 0.114 | 0.03 | 0.03 | -0.02 – 0.08 | 1.11 | 0.267 |
|
event_tot_s * activity_tot_s |
-0.00 | 0.00 | -0.01 – 0.00 | -0.53 | 0.599 | -0.00 | 0.00 | -0.00 – 0.00 | -0.15 | 0.882 | -0.00 | 0.00 | -0.01 – 0.01 | -0.62 | 0.537 |
|
activity_tot_s * social_tot_s |
0.00 | 0.00 | -0.00 – 0.01 | 1.38 | 0.167 | 0.00 | 0.00 | -0.00 – 0.00 | 1.77 | 0.077 | -0.00 | 0.00 | -0.01 – 0.01 | -0.18 | 0.860 |
| Random Effects | |||||||||||||||
| σ2 | 0.03 | 0.04 | 0.05 | ||||||||||||
| τ00 | 0.00 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | ||||||||||||
| 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||
| 0.01 castor_record_id.2 | 0.00 castor_record_id.2 | 0.02 castor_record_id.2 | |||||||||||||
| 0.02 castor_record_id.3 | 0.00 castor_record_id.3 | 0.03 castor_record_id.3 | |||||||||||||
| 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||
| 0.18 castor_record_id.5 | 0.02 castor_record_id.5 | 0.43 castor_record_id.5 | |||||||||||||
| τ11 | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | ||||||||||||
| 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | |||||||||||||
| 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | |||||||||||||
| ρ01 | -0.50 castor_record_id.activity_tot_s | 0.51 castor_record_id.activity_tot_s | -0.68 castor_record_id.activity_tot_s | ||||||||||||
| -0.16 castor_record_id.social_tot_s | 0.14 castor_record_id.social_tot_s | -0.07 castor_record_id.social_tot_s | |||||||||||||
| -0.35 castor_record_id.physical_tot_s | -0.55 castor_record_id.physical_tot_s | -0.67 castor_record_id.physical_tot_s | |||||||||||||
| ICC | 0.70 | 0.58 | |||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||
| Observations | 4711 | 4711 | 4711 | ||||||||||||
| Marginal R2 / Conditional R2 | 0.843 / 0.952 | 0.239 / NA | 0.882 / 0.950 | ||||||||||||
We now build the table for all the physiology measures, and apply the FDR correction to these models. These are the statistics we report in the article.
tab_model(glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
dv.labels=c("SC Tonic", "SC Number", "SC Magnitude", "SC AUC", "HR Mean", "HR Min", "HR Max"),
title="Table X. Momentary Physiology and Subjective Stress",
transform=NULL, p.adjust="fdr",
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| SC Tonic | SC Number | SC Magnitude | SC AUC | HR Mean | HR Min | HR Max | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Log-Mean | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.02 | 0.05 | -0.09 – 0.12 | 0.30 | 0.831 | 2.10 | 0.11 | 1.89 – 2.32 | 19.28 | <0.001 | 1.41 | 0.16 | 1.10 – 1.72 | 8.84 | <0.001 | 1.08 | 0.15 | 0.78 – 1.37 | 7.06 | <0.001 | 3.26 | 0.12 | 3.03 – 3.49 | 28.14 | <0.001 | 1.35 | 0.04 | 1.27 – 1.43 | 34.06 | <0.001 | 3.39 | 0.16 | 3.07 – 3.71 | 21.02 | <0.001 |
| event_tot_s | 0.01 | 0.01 | -0.01 – 0.03 | 1.03 | 0.648 | 0.04 | 0.03 | -0.01 – 0.10 | 1.55 | 0.158 | 0.07 | 0.03 | 0.02 – 0.12 | 2.78 | 0.012 | 0.02 | 0.02 | -0.02 – 0.07 | 1.00 | 0.545 | 0.01 | 0.02 | -0.02 – 0.05 | 0.72 | 0.611 | -0.00 | 0.01 | -0.01 – 0.01 | -0.19 | 0.882 | 0.02 | 0.03 | -0.04 – 0.07 | 0.59 | 0.718 |
| activity_tot_s | 0.01 | 0.01 | -0.01 – 0.03 | 0.76 | 0.648 | 0.06 | 0.03 | -0.01 – 0.13 | 1.78 | 0.109 | 0.05 | 0.03 | -0.01 – 0.11 | 1.64 | 0.145 | 0.03 | 0.03 | -0.03 – 0.08 | 0.85 | 0.545 | -0.01 | 0.02 | -0.05 – 0.03 | -0.44 | 0.716 | -0.01 | 0.01 | -0.03 – 0.00 | -1.40 | 0.209 | 0.03 | 0.03 | -0.04 – 0.09 | 0.85 | 0.646 |
| social_tot_s | 0.00 | 0.01 | -0.01 – 0.02 | 0.49 | 0.738 | 0.01 | 0.03 | -0.05 – 0.07 | 0.37 | 0.769 | -0.02 | 0.02 | -0.06 – 0.03 | -0.78 | 0.565 | 0.00 | 0.02 | -0.04 – 0.05 | 0.13 | 0.893 | -0.03 | 0.02 | -0.06 – 0.00 | -1.70 | 0.144 | -0.01 | 0.01 | -0.02 – -0.00 | -2.30 | 0.046 | -0.00 | 0.02 | -0.05 – 0.05 | -0.02 | 0.986 |
| physical_tot_s | -0.00 | 0.00 | -0.01 – 0.00 | -0.86 | 0.648 | 0.02 | 0.03 | -0.04 – 0.08 | 0.60 | 0.646 | 0.03 | 0.01 | 0.00 – 0.05 | 2.18 | 0.047 | 0.01 | 0.01 | -0.01 – 0.03 | 0.81 | 0.545 | 0.02 | 0.01 | -0.00 – 0.03 | 1.75 | 0.144 | 0.00 | 0.00 | -0.00 – 0.01 | 0.85 | 0.466 | 0.01 | 0.01 | -0.02 – 0.03 | 0.45 | 0.772 |
| ema_beep | 0.00 | 0.00 | -0.00 – 0.01 | 0.56 | 0.738 | -0.05 | 0.02 | -0.10 – -0.00 | -2.11 | 0.056 | -0.00 | 0.01 | -0.02 – 0.02 | -0.26 | 0.793 | 0.01 | 0.01 | -0.01 – 0.03 | 1.28 | 0.432 | -0.04 | 0.01 | -0.06 – -0.03 | -6.24 | <0.001 | -0.01 | 0.00 | -0.02 – -0.01 | -4.87 | <0.001 | -0.05 | 0.01 | -0.07 – -0.03 | -5.44 | <0.001 |
| Sex [Male] | -0.00 | 0.02 | -0.04 – 0.04 | -0.04 | 0.969 | 0.83 | 0.11 | 0.62 – 1.05 | 7.52 | <0.001 | 0.04 | 0.07 | -0.10 – 0.18 | 0.56 | 0.682 | 0.05 | 0.06 | -0.08 – 0.17 | 0.72 | 0.555 | -0.00 | 0.06 | -0.13 – 0.12 | -0.08 | 0.936 | -0.08 | 0.02 | -0.11 – -0.04 | -3.74 | <0.001 | 0.15 | 0.07 | 0.02 – 0.29 | 2.29 | 0.047 |
| physical_excercise_dur | 0.06 | 0.04 | -0.03 – 0.14 | 1.28 | 0.648 | -0.06 | 0.38 | -0.81 – 0.69 | -0.16 | 0.875 | 0.35 | 0.12 | 0.11 – 0.59 | 2.87 | 0.011 | 0.21 | 0.10 | 0.01 – 0.42 | 2.04 | 0.108 | 0.46 | 0.09 | 0.29 – 0.63 | 5.33 | <0.001 | 0.11 | 0.03 | 0.05 – 0.16 | 3.81 | <0.001 | 0.42 | 0.13 | 0.17 – 0.67 | 3.28 | 0.003 |
| acc_delta | 0.02 | 0.00 | 0.01 – 0.02 | 9.41 | <0.001 | 0.22 | 0.01 | 0.20 – 0.25 | 16.63 | <0.001 | 0.11 | 0.01 | 0.10 – 0.12 | 18.48 | <0.001 | 0.12 | 0.01 | 0.11 – 0.13 | 16.69 | <0.001 | 0.14 | 0.00 | 0.13 – 0.15 | 30.03 | <0.001 | 0.02 | 0.00 | 0.02 – 0.02 | 19.57 | <0.001 | 0.18 | 0.01 | 0.17 – 0.19 | 29.12 | <0.001 |
| temp_mean_z | 0.04 | 0.01 | 0.02 – 0.06 | 4.45 | <0.001 | 0.45 | 0.09 | 0.27 – 0.63 | 4.84 | <0.001 | 0.12 | 0.03 | 0.07 – 0.17 | 4.90 | <0.001 | 0.13 | 0.02 | 0.08 – 0.17 | 5.04 | <0.001 | -0.09 | 0.02 | -0.14 – -0.05 | -4.42 | <0.001 | 0.01 | 0.01 | -0.00 – 0.03 | 1.73 | 0.136 | -0.23 | 0.03 | -0.28 – -0.17 | -7.96 | <0.001 |
| temp_slope_z | 0.03 | 0.01 | 0.01 – 0.04 | 2.78 | 0.023 | 0.25 | 0.07 | 0.11 – 0.38 | 3.45 | 0.001 | 0.07 | 0.02 | 0.03 – 0.12 | 3.44 | 0.002 | 0.09 | 0.02 | 0.04 – 0.13 | 3.75 | 0.001 | 0.03 | 0.02 | -0.00 – 0.07 | 1.70 | 0.144 | 0.01 | 0.01 | -0.00 – 0.02 | 1.58 | 0.165 | 0.03 | 0.03 | -0.02 – 0.08 | 1.11 | 0.496 |
|
event_tot_s * activity_tot_s |
-0.00 | 0.00 | -0.00 – 0.00 | -0.95 | 0.648 | -0.01 | 0.00 | -0.01 – -0.00 | -2.37 | 0.033 | -0.01 | 0.00 | -0.02 – -0.00 | -2.43 | 0.028 | -0.00 | 0.00 | -0.01 – 0.01 | -0.81 | 0.545 | -0.00 | 0.00 | -0.01 – 0.00 | -0.53 | 0.708 | -0.00 | 0.00 | -0.00 – 0.00 | -0.15 | 0.882 | -0.00 | 0.00 | -0.01 – 0.01 | -0.62 | 0.718 |
|
activity_tot_s * social_tot_s |
-0.00 | 0.00 | -0.00 – 0.00 | -0.78 | 0.648 | -0.01 | 0.00 | -0.01 – -0.00 | -3.06 | 0.005 | 0.00 | 0.00 | -0.01 – 0.01 | 0.33 | 0.793 | -0.00 | 0.00 | -0.01 – 0.01 | -0.62 | 0.582 | 0.00 | 0.00 | -0.00 – 0.01 | 1.38 | 0.242 | 0.00 | 0.00 | -0.00 – 0.00 | 1.77 | 0.136 | -0.00 | 0.00 | -0.01 – 0.01 | -0.18 | 0.932 |
| Random Effects | |||||||||||||||||||||||||||||||||||
| σ2 | 0.08 | 0.25 | 0.17 | 0.25 | 0.03 | 0.04 | 0.05 | ||||||||||||||||||||||||||||
| τ00 | 0.00 castor_record_id | 0.04 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | 0.00 castor_record_id | ||||||||||||||||||||||||||||
| 0.00 castor_record_id.1 | 0.04 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.2 | 0.40 castor_record_id.2 | 0.01 castor_record_id.2 | 0.02 castor_record_id.2 | 0.01 castor_record_id.2 | 0.00 castor_record_id.2 | 0.02 castor_record_id.2 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.3 | 0.68 castor_record_id.3 | 0.03 castor_record_id.3 | 0.03 castor_record_id.3 | 0.02 castor_record_id.3 | 0.00 castor_record_id.3 | 0.03 castor_record_id.3 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.4 | 0.01 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||||||||||||||||||
| 0.06 castor_record_id.5 | 11.03 castor_record_id.5 | 0.37 castor_record_id.5 | 0.19 castor_record_id.5 | 0.18 castor_record_id.5 | 0.02 castor_record_id.5 | 0.43 castor_record_id.5 | |||||||||||||||||||||||||||||
| τ11 | 0.00 castor_record_id.activity_tot_s | 0.06 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | 0.00 castor_record_id.activity_tot_s | ||||||||||||||||||||||||||||
| 0.00 castor_record_id.social_tot_s | 0.05 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | 0.00 castor_record_id.social_tot_s | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.physical_tot_s | 0.07 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | 0.00 castor_record_id.physical_tot_s | |||||||||||||||||||||||||||||
| ρ01 | -0.51 castor_record_id.activity_tot_s | -0.24 castor_record_id.activity_tot_s | -0.43 castor_record_id.activity_tot_s | -0.04 castor_record_id.activity_tot_s | -0.50 castor_record_id.activity_tot_s | 0.51 castor_record_id.activity_tot_s | -0.68 castor_record_id.activity_tot_s | ||||||||||||||||||||||||||||
| -0.61 castor_record_id.social_tot_s | -0.11 castor_record_id.social_tot_s | -0.42 castor_record_id.social_tot_s | -0.59 castor_record_id.social_tot_s | -0.16 castor_record_id.social_tot_s | 0.14 castor_record_id.social_tot_s | -0.07 castor_record_id.social_tot_s | |||||||||||||||||||||||||||||
| -0.53 castor_record_id.physical_tot_s | -0.28 castor_record_id.physical_tot_s | -0.30 castor_record_id.physical_tot_s | -0.31 castor_record_id.physical_tot_s | -0.35 castor_record_id.physical_tot_s | -0.55 castor_record_id.physical_tot_s | -0.67 castor_record_id.physical_tot_s | |||||||||||||||||||||||||||||
| ICC | 0.07 | 0.88 | 0.33 | 0.17 | 0.70 | 0.58 | |||||||||||||||||||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | 4711 | 4711 | 4711 | ||||||||||||||||||||||||||||
| Marginal R2 / Conditional R2 | 0.094 / 0.161 | 0.417 / 0.931 | 0.534 / 0.690 | 0.532 / 0.609 | 0.843 / 0.952 | 0.239 / NA | 0.882 / 0.950 | ||||||||||||||||||||||||||||
Next we plot our outcomes as a function of the subjective stress. We build four graphs, one for each of the subjective stress types. These graphs are presented in the results section of the article (figure 3).
# Shorrtlist the variables to those of interest
plot.vars <- plot_models(glmer.posmood_beep, glmer.sc_ph_num_ema, glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema)
# Get and filter terms
full_term <- as.vector(plot.vars$data$term[1:length(plot.vars$data$term)])
event_term <- full_term[full_term != "event_tot_s"]
activ_term <-full_term[full_term != "activity_tot_s"]
soc_term <- full_term[full_term != "social_tot_s"]
phy_term <- full_term[full_term != "physical_tot_s"]
# Set the colours
col_list <-c('#7570B3','#7570B3','#7570B3',"#D95F02", "#D95F02", '#D95F02', '#D95F02', "#1B9E77", "#1B9E77")
# Event Plot
plot.event_substr <- plot_models(glmer.posmood_beep, glmer.negmood_beep,
glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
m.labels=c("Positive Affect", "Negative Affect", "SC Tonic", "SC Number", "SC Magnitued", "SC AUC", "HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(""),
# Stastistical Stuff
rm.terms = event_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size = 0.5,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme +
theme(axis.ticks.y=element_blank(),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
plot.event_substr <- plot.event_substr+ coord_flip(ylim=c(0.75,1.25)) + coord_flip(ylim=c(-0.5,0.5)) + theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_StrResid_Event.tiff", units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
# Act Plot
plot.activity_substr <- plot_models(glmer.posmood_beep, glmer.negmood_beep,
glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
m.labels=c("Positive Affect", "Negative Affect", "SC Tonic", "SC Number", "SC Magnitued", "SC AUC", "HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(""),
# Stastistical Stuff
rm.terms = activ_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size = 0.5,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme +
theme(axis.ticks.y=element_blank(),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
plot.activity_substr <- plot.activity_substr+ coord_flip(ylim=c(0.75,1.25)) + coord_flip(ylim=c(-0.5,0.5)) + theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_StrResid_Activity.tiff", units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
# Social Stress
plot.social_substr <- plot_models(glmer.posmood_beep, glmer.negmood_beep,
glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
m.labels=c("Positive Affect", "Negative Affect", "SC Tonic", "SC Number", "SC Magnitued", "SC AUC", "HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(""),
# Stastistical Stuff
rm.terms = soc_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size = 0.5,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme +
theme(axis.ticks.y=element_blank(),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
## Plot
plot.social_substr <- plot.social_substr + coord_flip(ylim=c(0.75,1.25)) + coord_flip(ylim=c(-0.5,0.5)) + theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_StrResid_Social.tiff", units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
# Physical Stress
plot.physical_substr <- plot_models(glmer.posmood_beep, glmer.negmood_beep,
glmer.sc_ton_ema, glmer.sc_ph_num_ema, glmer.sc_ph_mag_ema, glmer.sc_ph_auc_ema,
glmer.hr_mean_ema, glmer.hr_min_ema, glmer.hr_max_ema,
m.labels=c("Positive Affect", "Negative Affect", "SC Tonic", "SC Number", "SC Magnitued", "SC AUC", "HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(""),
# Stastistical Stuff
rm.terms = phy_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size =0.5,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme +
theme(axis.ticks.y=element_blank(),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
# Plot
plot.physical_substr <- plot.physical_substr + coord_flip(ylim=c(-0.5,0.5), xlim=c(1,1.1)) + theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank())
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_StrResid_Physical.tiff", units="in", width=4, height=4, dpi=300, compression = 'lzw', bg="transparent")
# All
ggarrange(plot.event_substr, plot.activity_substr, plot.social_substr, plot.physical_substr, common.legend = T, legend="right")
font family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font databasefont family 'Calibri' not found in PostScript font database
#ggsave("figures/fig_StrResid_MAT.tiff", units="in", width=7, height=7, dpi=300, compression = 'lzw', bg="transparent")
So we only see event related and physical stress have a relationship with SC magnitude. Thats cools, and somewhat replicates some previous findings from Smets et al. 2018.
Since we think this is an arousal related mechanism, we would also need to establish the link to physiology. To this end, we check the relationship between physiology and the mood items. We see a high correlation between positive and negative mood (presented below). So we also model interaction terms here. Due to model convergence issues, we only model the fixed intercepts here for the fixe effects of interest. Again, we check all model families before we pick the one with the best fit.
# Model
glmer.sc_ton_mood <- glmer(sc_tonic_mean_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(0+mood_positive_s*mood_negative_s| castor_record_id) +# + (1+mood_negative_s|castor_record_id)+
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.sc_ton_mood)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: sc_tonic_mean_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(0 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
826.0 968.8 -391.0 782.0 4849
Scaled residuals:
Min 1Q Median 3Q Max
-2.1179 -0.3349 -0.1231 0.0591 19.0949
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id mood_positive_s 0.0002771 0.01665
mood_negative_s 0.0011174 0.03343 0.49
mood_positive_s:mood_negative_s 0.0001141 0.01068 -0.83 -0.88
castor_record_id.1 ema_beep 0.0002370 0.01540
castor_record_id.2 temp_slope_z 0.0039451 0.06281
castor_record_id.3 temp_mean_z 0.0038193 0.06180
castor_record_id.4 acc_delta 0.0001949 0.01396
castor_record_id.5 physical_excercise_dur 0.0741943 0.27239
Residual 0.0838519 0.28957
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.0396304 0.0438377 0.904 0.36598
mood_positive_s 0.0042376 0.0064384 0.658 0.51042
mood_negative_s -0.0050873 0.0115797 -0.439 0.66042
ema_beep 0.0021828 0.0031432 0.694 0.48739
SexMale -0.0153771 0.0194991 -0.789 0.43034
temp_slope_z 0.0306751 0.0095179 3.223 0.00127 **
temp_mean_z 0.0428873 0.0091208 4.702 2.57e-06 ***
acc_delta 0.0186543 0.0018802 9.922 < 2e-16 ***
physical_excercise_dur 0.0767597 0.0465881 1.648 0.09943 .
mood_positive_s:mood_negative_s -0.0007453 0.0022761 -0.327 0.74333
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.864
mood_ngtv_s -0.734 0.807
ema_beep -0.115 -0.069 -0.043
SexMale -0.191 -0.003 0.033 0.005
temp_slop_z -0.016 0.006 0.008 -0.009 -0.004
temp_mean_z 0.028 -0.021 -0.005 -0.088 -0.022 0.030
acc_delta -0.062 -0.012 -0.004 0.037 -0.010 0.055 0.064
physcl_xcr_ 0.007 -0.042 -0.017 -0.005 0.011 0.001 0.018 0.000
md_pstv_:__ 0.504 -0.746 -0.890 0.036 0.004 -0.007 0.001 0.008 0.019
# Summary
summary(glmer.sc_phnum_mood)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: sc_phasic_num_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
14741.2 14910.0 -7344.6 14689.2 4845
Scaled residuals:
Min 1Q Median 3Q Max
-1.4581 -0.6350 -0.2565 0.3914 6.9950
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 0.350643 0.59215
mood_positive_s 0.007978 0.08932 -0.70
mood_negative_s 0.022776 0.15092 -0.40 0.59
mood_positive_s:mood_negative_s 0.001555 0.03943 -0.03 -0.52 -0.72
castor_record_id.1 ema_beep 0.004044 0.06360
castor_record_id.2 temp_slope_z 0.032105 0.17918
castor_record_id.3 temp_mean_z 0.058193 0.24123
castor_record_id.4 acc_delta 0.005839 0.07642
castor_record_id.5 physical_excercise_dur 0.210590 0.45890
Residual 0.345717 0.58798
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.052598 0.200174 5.258 1.45e-07 ***
mood_positive_s 0.042101 0.028490 1.478 0.13948
mood_negative_s 0.064857 0.050329 1.289 0.19752
ema_beep 0.005401 0.012700 0.425 0.67065
SexMale 0.176571 0.101192 1.745 0.08100 .
temp_slope_z 0.130446 0.034084 3.827 0.00013 ***
temp_mean_z 0.220188 0.036426 6.045 1.50e-09 ***
acc_delta 0.208540 0.010920 19.097 < 2e-16 ***
physical_excercise_dur 0.194629 0.138589 1.404 0.16021
mood_positive_s:mood_negative_s -0.009994 0.009407 -1.062 0.28806
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.877
mood_ngtv_s -0.739 0.812
ema_beep -0.086 -0.076 -0.049
SexMale -0.174 -0.024 0.002 -0.014
temp_slop_z -0.008 0.007 0.002 -0.026 -0.008
temp_mean_z 0.030 -0.016 -0.005 -0.100 -0.017 0.022
acc_delta -0.053 -0.023 -0.013 0.049 -0.023 0.046 0.049
physcl_xcr_ 0.023 -0.060 -0.031 -0.010 0.013 -0.004 0.016 -0.003
md_pstv_:__ 0.497 -0.723 -0.873 0.040 0.023 -0.004 0.001 0.014 0.031
convergence code: 0
failure to converge in 10000 evaluations
# Model
glmer.sc_ph_mag_mood <- glmer(sc_phasic_mag_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(1+mood_positive_s*mood_negative_s| castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="identity"),
control=glmerControl(calc.derivs = FALSE) )
failure to converge in 10000 evaluations
# Summary
summary(glmer.sc_ph_mag_mood)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( identity )
Formula: sc_phasic_mag_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
11913.3 12082.1 -5930.7 11861.3 4845
Scaled residuals:
Min 1Q Median 3Q Max
-1.8368 -0.6324 -0.1321 0.4525 8.7888
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 0.244456 0.49443
mood_positive_s 0.003084 0.05554 -0.35
mood_negative_s 0.001438 0.03792 0.50 0.35
mood_positive_s:mood_negative_s 0.001058 0.03253 -0.61 -0.37 -0.89
castor_record_id.1 ema_beep 0.001722 0.04150
castor_record_id.2 temp_slope_z 0.009954 0.09977
castor_record_id.3 temp_mean_z 0.021382 0.14623
castor_record_id.4 acc_delta 0.001572 0.03965
castor_record_id.5 physical_excercise_dur 0.350216 0.59179
Residual 0.166456 0.40799
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.552438 0.146466 10.599 < 2e-16 ***
mood_positive_s 0.047509 0.019803 2.399 0.01643 *
mood_negative_s 0.053930 0.031767 1.698 0.08957 .
ema_beep -0.004206 0.008899 -0.473 0.63646
SexMale 0.009777 0.078192 0.125 0.90050
temp_slope_z 0.070125 0.021517 3.259 0.00112 **
temp_mean_z 0.130808 0.023914 5.470 4.5e-08 ***
acc_delta 0.105776 0.005990 17.660 < 2e-16 ***
physical_excercise_dur 0.323006 0.121028 2.669 0.00761 **
mood_positive_s:mood_negative_s -0.013569 0.006703 -2.024 0.04294 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.825
mood_ngtv_s -0.694 0.811
ema_beep -0.100 -0.072 -0.043
SexMale -0.211 -0.011 0.020 -0.001
temp_slop_z -0.017 0.012 0.013 -0.019 -0.004
temp_mean_z 0.028 -0.016 -0.004 -0.109 -0.018 0.036
acc_delta -0.061 -0.023 -0.011 0.056 -0.012 0.064 0.066
physcl_xcr_ 0.013 -0.048 -0.023 -0.007 0.006 0.001 0.018 -0.003
md_pstv_:__ 0.324 -0.670 -0.814 0.033 0.018 -0.012 0.000 0.014 0.023
convergence code: 0
failure to converge in 10000 evaluations
# Model
glmer.sc_ph_auc_mood <- glmer(sc_phasic_auc_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(1+mood_positive_s*mood_negative_s| castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.sc_ph_auc_mood)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: sc_phasic_auc_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
10443.9 10612.7 -5195.9 10391.9 4845
Scaled residuals:
Min 1Q Median 3Q Max
-1.7404 -0.5545 -0.2722 0.1561 7.3519
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 0.3289788 0.57357
mood_positive_s 0.0056379 0.07509 -0.91
mood_negative_s 0.0146068 0.12086 -0.79 0.88
mood_positive_s:mood_negative_s 0.0005925 0.02434 0.45 -0.71 -0.85
castor_record_id.1 ema_beep 0.0008483 0.02913
castor_record_id.2 temp_slope_z 0.0073684 0.08584
castor_record_id.3 temp_mean_z 0.0123953 0.11133
castor_record_id.4 acc_delta 0.0004188 0.02047
castor_record_id.5 physical_excercise_dur 0.0863063 0.29378
Residual 0.2430242 0.49297
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 0.243959 0.105105 2.321 0.020281 *
mood_positive_s 0.010266 0.014198 0.723 0.469668
mood_negative_s 0.006440 0.024432 0.264 0.792089
ema_beep -0.004651 0.005552 -0.838 0.402168
SexMale 0.034131 0.045364 0.752 0.451820
temp_slope_z 0.052555 0.014331 3.667 0.000245 ***
temp_mean_z 0.089744 0.016284 5.511 3.56e-08 ***
acc_delta 0.046783 0.002903 16.116 < 2e-16 ***
physical_excercise_dur 0.067156 0.064732 1.037 0.299526
mood_positive_s:mood_negative_s -0.002741 0.004481 -0.612 0.540729
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.903
mood_ngtv_s -0.773 0.848
ema_beep -0.075 -0.057 -0.038
SexMale -0.182 0.000 0.025 0.008
temp_slop_z -0.014 0.006 0.009 -0.011 -0.005
temp_mean_z 0.015 -0.010 0.000 -0.089 -0.019 0.034
acc_delta -0.047 -0.013 -0.004 0.040 -0.004 0.067 0.069
physcl_xcr_ 0.007 -0.038 -0.017 -0.005 0.010 0.003 0.015 -0.001
md_pstv_:__ 0.532 -0.736 -0.891 0.034 0.006 -0.007 -0.002 0.007 0.021
Now we make a table, without the FDR correction. This we do later with the full modles in the table.
tab_model(glmer.sc_ton_mood, glmer.sc_phnum_mood, glmer.sc_ph_mag_mood, glmer.sc_ph_auc_mood,
dv.labels=c("Tonic", "Number", "Magnitude", "AUC"),
title="Table X. SCR and Mood",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Tonic | Number | Magnitude | AUC | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.04 | 0.04 | -0.05 – 0.13 | 0.90 | 0.366 | 1.05 | 0.20 | 0.66 – 1.44 | 5.26 | <0.001 | 1.55 | 0.15 | 1.27 – 1.84 | 10.60 | <0.001 | 0.24 | 0.11 | 0.04 – 0.45 | 2.32 | 0.020 |
| mood_positive_s | 0.00 | 0.01 | -0.01 – 0.02 | 0.66 | 0.510 | 0.04 | 0.03 | -0.01 – 0.10 | 1.48 | 0.139 | 0.05 | 0.02 | 0.01 – 0.09 | 2.40 | 0.016 | 0.01 | 0.01 | -0.02 – 0.04 | 0.72 | 0.470 |
| mood_negative_s | -0.01 | 0.01 | -0.03 – 0.02 | -0.44 | 0.660 | 0.06 | 0.05 | -0.03 – 0.16 | 1.29 | 0.198 | 0.05 | 0.03 | -0.01 – 0.12 | 1.70 | 0.090 | 0.01 | 0.02 | -0.04 – 0.05 | 0.26 | 0.792 |
| ema_beep | 0.00 | 0.00 | -0.00 – 0.01 | 0.69 | 0.487 | 0.01 | 0.01 | -0.02 – 0.03 | 0.43 | 0.671 | -0.00 | 0.01 | -0.02 – 0.01 | -0.47 | 0.636 | -0.00 | 0.01 | -0.02 – 0.01 | -0.84 | 0.402 |
| Sex [Male] | -0.02 | 0.02 | -0.05 – 0.02 | -0.79 | 0.430 | 0.18 | 0.10 | -0.02 – 0.37 | 1.74 | 0.081 | 0.01 | 0.08 | -0.14 – 0.16 | 0.13 | 0.900 | 0.03 | 0.05 | -0.05 – 0.12 | 0.75 | 0.452 |
| temp_slope_z | 0.03 | 0.01 | 0.01 – 0.05 | 3.22 | 0.001 | 0.13 | 0.03 | 0.06 – 0.20 | 3.83 | <0.001 | 0.07 | 0.02 | 0.03 – 0.11 | 3.26 | 0.001 | 0.05 | 0.01 | 0.02 – 0.08 | 3.67 | <0.001 |
| temp_mean_z | 0.04 | 0.01 | 0.03 – 0.06 | 4.70 | <0.001 | 0.22 | 0.04 | 0.15 – 0.29 | 6.04 | <0.001 | 0.13 | 0.02 | 0.08 – 0.18 | 5.47 | <0.001 | 0.09 | 0.02 | 0.06 – 0.12 | 5.51 | <0.001 |
| acc_delta | 0.02 | 0.00 | 0.01 – 0.02 | 9.92 | <0.001 | 0.21 | 0.01 | 0.19 – 0.23 | 19.10 | <0.001 | 0.11 | 0.01 | 0.09 – 0.12 | 17.66 | <0.001 | 0.05 | 0.00 | 0.04 – 0.05 | 16.12 | <0.001 |
| physical_excercise_dur | 0.08 | 0.05 | -0.01 – 0.17 | 1.65 | 0.099 | 0.19 | 0.14 | -0.08 – 0.47 | 1.40 | 0.160 | 0.32 | 0.12 | 0.09 – 0.56 | 2.67 | 0.008 | 0.07 | 0.06 | -0.06 – 0.19 | 1.04 | 0.300 |
|
mood_positive_s * mood_negative_s |
-0.00 | 0.00 | -0.01 – 0.00 | -0.33 | 0.743 | -0.01 | 0.01 | -0.03 – 0.01 | -1.06 | 0.288 | -0.01 | 0.01 | -0.03 – -0.00 | -2.02 | 0.043 | -0.00 | 0.00 | -0.01 – 0.01 | -0.61 | 0.541 |
| Random Effects | ||||||||||||||||||||
| σ2 | 0.08 | 0.35 | 0.17 | 0.24 | ||||||||||||||||
| τ00 | 0.00 castor_record_id | 0.35 castor_record_id | 0.24 castor_record_id | 0.33 castor_record_id | ||||||||||||||||
| 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||||||
| 0.00 castor_record_id.2 | 0.03 castor_record_id.2 | 0.01 castor_record_id.2 | 0.01 castor_record_id.2 | |||||||||||||||||
| 0.00 castor_record_id.3 | 0.06 castor_record_id.3 | 0.02 castor_record_id.3 | 0.01 castor_record_id.3 | |||||||||||||||||
| 0.00 castor_record_id.4 | 0.01 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||||||
| 0.07 castor_record_id.5 | 0.21 castor_record_id.5 | 0.35 castor_record_id.5 | 0.09 castor_record_id.5 | |||||||||||||||||
| τ11 | 0.00 castor_record_id.mood_negative_s | 0.01 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | 0.01 castor_record_id.mood_positive_s | ||||||||||||||||
| 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.02 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | 0.01 castor_record_id.mood_negative_s | |||||||||||||||||
| 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | ||||||||||||||||||
| ρ01 | 0.49 castor_record_id.mood_negative_s | -0.70 castor_record_id.mood_positive_s | -0.35 castor_record_id.mood_positive_s | -0.91 castor_record_id.mood_positive_s | ||||||||||||||||
| -0.83 castor_record_id.mood_positive_s:mood_negative_s | -0.40 castor_record_id.mood_negative_s | 0.50 castor_record_id.mood_negative_s | -0.79 castor_record_id.mood_negative_s | |||||||||||||||||
| -0.03 castor_record_id.mood_positive_s:mood_negative_s | -0.61 castor_record_id.mood_positive_s:mood_negative_s | 0.45 castor_record_id.mood_positive_s:mood_negative_s | ||||||||||||||||||
| ICC | 0.05 | 0.32 | 0.41 | 0.13 | ||||||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | ||||||||||||||||
| Marginal R2 / Conditional R2 | 0.104 / 0.152 | 0.678 / 0.780 | 0.500 / 0.706 | 0.173 / 0.281 | ||||||||||||||||
glmer.hr_mean_mood <- glmer(hr_mean_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(1+mood_positive_s*mood_negative_s| castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.hr_mean_mood)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: hr_mean_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
9058.4 9226.3 -4503.2 9006.4 4685
Scaled residuals:
Min 1Q Median 3Q Max
-3.4356 -0.5907 -0.0601 0.5214 10.2865
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 3.570e-02 0.188932
mood_positive_s 5.598e-04 0.023661 -0.90
mood_negative_s 1.263e-03 0.035535 -0.75 0.82
mood_positive_s:mood_negative_s 4.115e-05 0.006415 0.50 -0.69 -0.86
castor_record_id.1 ema_beep 1.250e-04 0.011179
castor_record_id.2 temp_slope_z 7.579e-04 0.027531
castor_record_id.3 temp_mean_z 1.872e-03 0.043270
castor_record_id.4 acc_delta 7.545e-05 0.008686
castor_record_id.5 physical_excercise_dur 1.188e-02 0.109011
Residual 3.128e-02 0.176858
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.117392 0.036654 30.485 < 2e-16 ***
mood_positive_s 0.012585 0.004853 2.593 0.00952 **
mood_negative_s 0.007865 0.008155 0.964 0.33481
ema_beep -0.016230 0.002060 -7.879 3.30e-15 ***
SexMale -0.054053 0.019959 -2.708 0.00676 **
temp_slope_z 0.007640 0.005154 1.482 0.13828
temp_mean_z -0.030468 0.006267 -4.862 1.16e-06 ***
acc_delta 0.033032 0.001208 27.354 < 2e-16 ***
physical_excercise_dur 0.105793 0.023580 4.487 7.24e-06 ***
mood_positive_s:mood_negative_s -0.001236 0.001430 -0.864 0.38733
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.889
mood_ngtv_s -0.753 0.828
ema_beep -0.072 -0.068 -0.043
SexMale -0.215 -0.004 0.017 0.003
temp_slop_z -0.016 0.012 0.012 -0.022 -0.004
temp_mean_z 0.019 -0.011 -0.002 -0.099 -0.025 0.048
acc_delta -0.046 -0.017 -0.006 0.046 -0.013 0.057 0.055
physcl_xcr_ 0.008 -0.038 -0.018 -0.008 0.005 0.004 0.019 -0.001
md_pstv_:__ 0.542 -0.733 -0.894 0.043 0.010 -0.013 -0.001 0.010 0.020
glmer.hr_min_mood <- glmer(hr_min_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(1+mood_positive_s*mood_negative_s| castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.hr_min_mood )
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: hr_min_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
10935.8 11103.7 -5441.9 10883.8 4685
Scaled residuals:
Min 1Q Median 3Q Max
-3.0925 -0.6435 -0.0494 0.5448 9.5294
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 3.516e-02 0.187506
mood_positive_s 5.268e-04 0.022952 -0.82
mood_negative_s 1.410e-03 0.037545 -0.59 0.76
mood_positive_s:mood_negative_s 4.890e-05 0.006993 0.28 -0.63 -0.81
castor_record_id.1 ema_beep 1.177e-04 0.010849
castor_record_id.2 temp_slope_z 1.089e-03 0.033002
castor_record_id.3 temp_mean_z 2.142e-03 0.046280
castor_record_id.4 acc_delta 5.494e-05 0.007412
castor_record_id.5 physical_excercise_dur 1.663e-02 0.128948
Residual 4.319e-02 0.207821
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.1862762 0.0405706 29.240 < 2e-16 ***
mood_positive_s 0.0131687 0.0053708 2.452 0.014210 *
mood_negative_s 0.0060687 0.0093739 0.647 0.517367
ema_beep -0.0112667 0.0022710 -4.961 7.01e-07 ***
SexMale -0.0865262 0.0232618 -3.720 0.000199 ***
temp_slope_z 0.0083430 0.0060915 1.370 0.170811
temp_mean_z 0.0157470 0.0069500 2.266 0.023466 *
acc_delta 0.0221211 0.0011661 18.970 < 2e-16 ***
physical_excercise_dur 0.1031611 0.0277242 3.721 0.000198 ***
mood_positive_s:mood_negative_s -0.0008534 0.0016382 -0.521 0.602399
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.869
mood_ngtv_s -0.717 0.813
ema_beep -0.081 -0.076 -0.047
SexMale -0.218 -0.016 -0.006 0.002
temp_slop_z -0.017 0.012 0.011 -0.022 -0.002
temp_mean_z 0.022 -0.012 -0.003 -0.110 -0.026 0.048
acc_delta -0.057 -0.021 -0.006 0.058 -0.011 0.068 0.067
physcl_xcr_ 0.009 -0.040 -0.018 -0.008 0.003 0.004 0.020 -0.001
md_pstv_:__ 0.493 -0.724 -0.885 0.046 0.033 -0.012 0.000 0.011 0.020
glmer.hr_max_mood <- glmer(hr_max_s ~ mood_positive_s*mood_negative_s +
ema_beep + # I will model the beep to factor circadian rhythms
Sex + temp_slope_z + temp_mean_z +
acc_delta + physical_excercise_dur +
(1+mood_positive_s*mood_negative_s| castor_record_id) +
(0+ema_beep|castor_record_id)+
(0+temp_slope_z|castor_record_id) + (0+temp_mean_z|castor_record_id)+
(0+acc_delta|castor_record_id) + (0+physical_excercise_dur|castor_record_id),
EMA_Data,
family=Gamma(link="log"),
control=glmerControl(calc.derivs = FALSE) )
# Summary
summary(glmer.hr_max_mood )
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Gamma ( log )
Formula: hr_max_s ~ mood_positive_s * mood_negative_s + ema_beep + Sex + temp_slope_z + temp_mean_z + acc_delta + physical_excercise_dur +
(1 + mood_positive_s * mood_negative_s | castor_record_id) + (0 + ema_beep | castor_record_id) + (0 + temp_slope_z | castor_record_id) +
(0 + temp_mean_z | castor_record_id) + (0 + acc_delta | castor_record_id) + (0 + physical_excercise_dur | castor_record_id)
Data: EMA_Data
Control: glmerControl(calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
12385.4 12553.3 -6166.7 12333.4 4685
Scaled residuals:
Min 1Q Median 3Q Max
-3.0237 -0.6361 -0.1246 0.5065 7.2837
Random effects:
Groups Name Variance Std.Dev. Corr
castor_record_id (Intercept) 3.809e-02 0.195169
mood_positive_s 7.842e-04 0.028003 -0.96
mood_negative_s 8.147e-04 0.028543 -0.85 0.84
mood_positive_s:mood_negative_s 2.729e-05 0.005224 0.56 -0.66 -0.81
castor_record_id.1 ema_beep 1.442e-04 0.012008
castor_record_id.2 temp_slope_z 9.113e-04 0.030187
castor_record_id.3 temp_mean_z 2.359e-03 0.048567
castor_record_id.4 acc_delta 6.594e-05 0.008121
castor_record_id.5 physical_excercise_dur 2.309e-02 0.151961
Residual 5.140e-02 0.226724
Number of obs: 4711, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.210090 0.041917 28.868 < 2e-16 ***
mood_positive_s 0.012317 0.005875 2.097 0.0360 *
mood_negative_s 0.010179 0.008754 1.163 0.2449
ema_beep -0.016554 0.002477 -6.682 2.35e-11 ***
SexMale 0.030808 0.017140 1.797 0.0723 .
temp_slope_z 0.005902 0.006164 0.958 0.3383
temp_mean_z -0.061956 0.007289 -8.500 < 2e-16 ***
acc_delta 0.033853 0.001269 26.675 < 2e-16 ***
physical_excercise_dur 0.087195 0.031062 2.807 0.0050 **
mood_positive_s:mood_negative_s -0.001865 0.001553 -1.201 0.2299
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) md_ps_ md_ng_ ema_bp SexMal tmp_s_ tmp_m_ acc_dl phys__
mood_pstv_s -0.917
mood_ngtv_s -0.783 0.828
ema_beep -0.088 -0.070 -0.049
SexMale -0.171 0.003 0.038 0.000
temp_slop_z -0.019 0.013 0.015 -0.024 -0.005
temp_mean_z 0.030 -0.020 -0.008 -0.104 -0.032 0.052
acc_delta -0.059 -0.019 -0.006 0.058 -0.018 0.070 0.064
physcl_xcr_ 0.008 -0.039 -0.018 -0.008 0.007 0.004 0.022 0.000
md_pstv_:__ 0.566 -0.723 -0.892 0.048 -0.003 -0.016 0.003 0.011 0.020
Again, we make a table of the heart rate measures without the FDR correction. We apply that later.
tab_model(glmer.hr_mean_mood, glmer.hr_min_mood, glmer.hr_max_mood,
dv.labels=c("Mean", "Min", "Max"),
title="Table X. Heart rate vs. Mood",
transform=NULL,
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| Mean | Min | Max | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 1.12 | 0.04 | 1.05 – 1.19 | 30.48 | <0.001 | 1.19 | 0.04 | 1.11 – 1.27 | 29.24 | <0.001 | 1.21 | 0.04 | 1.13 – 1.29 | 28.87 | <0.001 |
| mood_positive_s | 0.01 | 0.00 | 0.00 – 0.02 | 2.59 | 0.010 | 0.01 | 0.01 | 0.00 – 0.02 | 2.45 | 0.014 | 0.01 | 0.01 | 0.00 – 0.02 | 2.10 | 0.036 |
| mood_negative_s | 0.01 | 0.01 | -0.01 – 0.02 | 0.96 | 0.335 | 0.01 | 0.01 | -0.01 – 0.02 | 0.65 | 0.517 | 0.01 | 0.01 | -0.01 – 0.03 | 1.16 | 0.245 |
| ema_beep | -0.02 | 0.00 | -0.02 – -0.01 | -7.88 | <0.001 | -0.01 | 0.00 | -0.02 – -0.01 | -4.96 | <0.001 | -0.02 | 0.00 | -0.02 – -0.01 | -6.68 | <0.001 |
| Sex [Male] | -0.05 | 0.02 | -0.09 – -0.01 | -2.71 | 0.007 | -0.09 | 0.02 | -0.13 – -0.04 | -3.72 | <0.001 | 0.03 | 0.02 | -0.00 – 0.06 | 1.80 | 0.072 |
| temp_slope_z | 0.01 | 0.01 | -0.00 – 0.02 | 1.48 | 0.138 | 0.01 | 0.01 | -0.00 – 0.02 | 1.37 | 0.171 | 0.01 | 0.01 | -0.01 – 0.02 | 0.96 | 0.338 |
| temp_mean_z | -0.03 | 0.01 | -0.04 – -0.02 | -4.86 | <0.001 | 0.02 | 0.01 | 0.00 – 0.03 | 2.27 | 0.023 | -0.06 | 0.01 | -0.08 – -0.05 | -8.50 | <0.001 |
| acc_delta | 0.03 | 0.00 | 0.03 – 0.04 | 27.35 | <0.001 | 0.02 | 0.00 | 0.02 – 0.02 | 18.97 | <0.001 | 0.03 | 0.00 | 0.03 – 0.04 | 26.68 | <0.001 |
| physical_excercise_dur | 0.11 | 0.02 | 0.06 – 0.15 | 4.49 | <0.001 | 0.10 | 0.03 | 0.05 – 0.16 | 3.72 | <0.001 | 0.09 | 0.03 | 0.03 – 0.15 | 2.81 | 0.005 |
|
mood_positive_s * mood_negative_s |
-0.00 | 0.00 | -0.00 – 0.00 | -0.86 | 0.387 | -0.00 | 0.00 | -0.00 – 0.00 | -0.52 | 0.602 | -0.00 | 0.00 | -0.00 – 0.00 | -1.20 | 0.230 |
| Random Effects | |||||||||||||||
| σ2 | 0.03 | 0.04 | 0.05 | ||||||||||||
| τ00 | 0.04 castor_record_id | 0.04 castor_record_id | 0.04 castor_record_id | ||||||||||||
| 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||
| 0.00 castor_record_id.2 | 0.00 castor_record_id.2 | 0.00 castor_record_id.2 | |||||||||||||
| 0.00 castor_record_id.3 | 0.00 castor_record_id.3 | 0.00 castor_record_id.3 | |||||||||||||
| 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||
| 0.01 castor_record_id.5 | 0.02 castor_record_id.5 | 0.02 castor_record_id.5 | |||||||||||||
| τ11 | 0.00 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | ||||||||||||
| 0.00 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | |||||||||||||
| 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | |||||||||||||
| ρ01 | -0.90 castor_record_id.mood_positive_s | -0.82 castor_record_id.mood_positive_s | -0.96 castor_record_id.mood_positive_s | ||||||||||||
| -0.75 castor_record_id.mood_negative_s | -0.59 castor_record_id.mood_negative_s | -0.85 castor_record_id.mood_negative_s | |||||||||||||
| 0.50 castor_record_id.mood_positive_s:mood_negative_s | 0.28 castor_record_id.mood_positive_s:mood_negative_s | 0.56 castor_record_id.mood_positive_s:mood_negative_s | |||||||||||||
| ICC | 0.17 | 0.18 | 0.07 | ||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||
| Observations | 4711 | 4711 | 4711 | ||||||||||||
| Marginal R2 / Conditional R2 | 0.448 / 0.540 | 0.216 / 0.354 | 0.387 / 0.427 | ||||||||||||
Now I can actually print the tables, and the plot along with the FDR correction.
tab_model(glmer.sc_ton_mood, glmer.sc_phnum_mood, glmer.sc_ph_mag_mood, glmer.sc_ph_auc_mood,
glmer.hr_mean_mood, glmer.hr_min_mood, glmer.hr_max_mood,
dv.labels=c("SC Tonic", "SC Number", "SC Magnitude", "SC AUC", "HR Mean", "HR Min", "HR Max"),
title="Table X. Physio vs. Mood",
transform=NULL, p.adjust="fdr",
show.stat=TRUE,
show.se=TRUE) %>%
return() %$%
knitr %>%
asis_output()
| SC Tonic | SC Number | SC Magnitude | SC AUC | HR Mean | HR Min | HR Max | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p | Estimates | std. Error | CI | Statistic | p |
| (Intercept) | 0.04 | 0.04 | -0.05 – 0.13 | 0.90 | 0.638 | 1.05 | 0.20 | 0.66 – 1.44 | 5.26 | <0.001 | 1.55 | 0.15 | 1.27 – 1.84 | 10.60 | <0.001 | 0.24 | 0.11 | 0.04 – 0.45 | 2.32 | 0.051 | 1.12 | 0.04 | 1.05 – 1.19 | 30.48 | <0.001 | 1.19 | 0.04 | 1.11 – 1.27 | 29.24 | <0.001 | 1.21 | 0.04 | 1.13 – 1.29 | 28.87 | <0.001 |
| mood_positive_s | 0.00 | 0.01 | -0.01 – 0.02 | 0.66 | 0.638 | 0.04 | 0.03 | -0.01 – 0.10 | 1.48 | 0.229 | 0.05 | 0.02 | 0.01 – 0.09 | 2.40 | 0.027 | 0.01 | 0.01 | -0.02 – 0.04 | 0.72 | 0.587 | 0.01 | 0.00 | 0.00 – 0.02 | 2.59 | 0.014 | 0.01 | 0.01 | 0.00 – 0.02 | 2.45 | 0.024 | 0.01 | 0.01 | 0.00 – 0.02 | 2.10 | 0.060 |
| mood_negative_s | -0.01 | 0.01 | -0.03 – 0.02 | -0.44 | 0.734 | 0.06 | 0.05 | -0.03 – 0.16 | 1.29 | 0.247 | 0.05 | 0.03 | -0.01 – 0.12 | 1.70 | 0.112 | 0.01 | 0.02 | -0.04 – 0.05 | 0.26 | 0.792 | 0.01 | 0.01 | -0.01 – 0.02 | 0.96 | 0.372 | 0.01 | 0.01 | -0.01 – 0.02 | 0.65 | 0.575 | 0.01 | 0.01 | -0.01 – 0.03 | 1.16 | 0.272 |
| ema_beep | 0.00 | 0.00 | -0.00 – 0.01 | 0.69 | 0.638 | 0.01 | 0.01 | -0.02 – 0.03 | 0.43 | 0.671 | -0.00 | 0.01 | -0.02 – 0.01 | -0.47 | 0.707 | -0.00 | 0.01 | -0.02 – 0.01 | -0.84 | 0.587 | -0.02 | 0.00 | -0.02 – -0.01 | -7.88 | <0.001 | -0.01 | 0.00 | -0.02 – -0.01 | -4.96 | <0.001 | -0.02 | 0.00 | -0.02 – -0.01 | -6.68 | <0.001 |
| Sex [Male] | -0.02 | 0.02 | -0.05 – 0.02 | -0.79 | 0.638 | 0.18 | 0.10 | -0.02 – 0.37 | 1.74 | 0.162 | 0.01 | 0.08 | -0.14 – 0.16 | 0.13 | 0.900 | 0.03 | 0.05 | -0.05 – 0.12 | 0.75 | 0.587 | -0.05 | 0.02 | -0.09 – -0.01 | -2.71 | 0.011 | -0.09 | 0.02 | -0.13 – -0.04 | -3.72 | <0.001 | 0.03 | 0.02 | -0.00 – 0.06 | 1.80 | 0.103 |
| temp_slope_z | 0.03 | 0.01 | 0.01 – 0.05 | 3.22 | 0.004 | 0.13 | 0.03 | 0.06 – 0.20 | 3.83 | <0.001 | 0.07 | 0.02 | 0.03 – 0.11 | 3.26 | 0.003 | 0.05 | 0.01 | 0.02 – 0.08 | 3.67 | 0.001 | 0.01 | 0.01 | -0.00 – 0.02 | 1.48 | 0.173 | 0.01 | 0.01 | -0.00 – 0.02 | 1.37 | 0.214 | 0.01 | 0.01 | -0.01 – 0.02 | 0.96 | 0.338 |
| temp_mean_z | 0.04 | 0.01 | 0.03 – 0.06 | 4.70 | <0.001 | 0.22 | 0.04 | 0.15 – 0.29 | 6.04 | <0.001 | 0.13 | 0.02 | 0.08 – 0.18 | 5.47 | <0.001 | 0.09 | 0.02 | 0.06 – 0.12 | 5.51 | <0.001 | -0.03 | 0.01 | -0.04 – -0.02 | -4.86 | <0.001 | 0.02 | 0.01 | 0.00 – 0.03 | 2.27 | 0.034 | -0.06 | 0.01 | -0.08 – -0.05 | -8.50 | <0.001 |
| acc_delta | 0.02 | 0.00 | 0.01 – 0.02 | 9.92 | <0.001 | 0.21 | 0.01 | 0.19 – 0.23 | 19.10 | <0.001 | 0.11 | 0.01 | 0.09 – 0.12 | 17.66 | <0.001 | 0.05 | 0.00 | 0.04 – 0.05 | 16.12 | <0.001 | 0.03 | 0.00 | 0.03 – 0.04 | 27.35 | <0.001 | 0.02 | 0.00 | 0.02 – 0.02 | 18.97 | <0.001 | 0.03 | 0.00 | 0.03 – 0.04 | 26.68 | <0.001 |
| physical_excercise_dur | 0.08 | 0.05 | -0.01 – 0.17 | 1.65 | 0.249 | 0.19 | 0.14 | -0.08 – 0.47 | 1.40 | 0.229 | 0.32 | 0.12 | 0.09 – 0.56 | 2.67 | 0.015 | 0.07 | 0.06 | -0.06 – 0.19 | 1.04 | 0.587 | 0.11 | 0.02 | 0.06 – 0.15 | 4.49 | <0.001 | 0.10 | 0.03 | 0.05 – 0.16 | 3.72 | <0.001 | 0.09 | 0.03 | 0.03 – 0.15 | 2.81 | 0.010 |
|
mood_positive_s * mood_negative_s |
-0.00 | 0.00 | -0.01 – 0.00 | -0.33 | 0.743 | -0.01 | 0.01 | -0.03 – 0.01 | -1.06 | 0.320 | -0.01 | 0.01 | -0.03 – -0.00 | -2.02 | 0.061 | -0.00 | 0.00 | -0.01 – 0.01 | -0.61 | 0.601 | -0.00 | 0.00 | -0.00 – 0.00 | -0.86 | 0.387 | -0.00 | 0.00 | -0.00 – 0.00 | -0.52 | 0.602 | -0.00 | 0.00 | -0.00 – 0.00 | -1.20 | 0.272 |
| Random Effects | |||||||||||||||||||||||||||||||||||
| σ2 | 0.08 | 0.35 | 0.17 | 0.24 | 0.03 | 0.04 | 0.05 | ||||||||||||||||||||||||||||
| τ00 | 0.00 castor_record_id | 0.35 castor_record_id | 0.24 castor_record_id | 0.33 castor_record_id | 0.04 castor_record_id | 0.04 castor_record_id | 0.04 castor_record_id | ||||||||||||||||||||||||||||
| 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | 0.00 castor_record_id.1 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.2 | 0.03 castor_record_id.2 | 0.01 castor_record_id.2 | 0.01 castor_record_id.2 | 0.00 castor_record_id.2 | 0.00 castor_record_id.2 | 0.00 castor_record_id.2 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.3 | 0.06 castor_record_id.3 | 0.02 castor_record_id.3 | 0.01 castor_record_id.3 | 0.00 castor_record_id.3 | 0.00 castor_record_id.3 | 0.00 castor_record_id.3 | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.4 | 0.01 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | 0.00 castor_record_id.4 | |||||||||||||||||||||||||||||
| 0.07 castor_record_id.5 | 0.21 castor_record_id.5 | 0.35 castor_record_id.5 | 0.09 castor_record_id.5 | 0.01 castor_record_id.5 | 0.02 castor_record_id.5 | 0.02 castor_record_id.5 | |||||||||||||||||||||||||||||
| τ11 | 0.00 castor_record_id.mood_negative_s | 0.01 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | 0.01 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | 0.00 castor_record_id.mood_positive_s | ||||||||||||||||||||||||||||
| 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.02 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | 0.01 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | 0.00 castor_record_id.mood_negative_s | |||||||||||||||||||||||||||||
| 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | 0.00 castor_record_id.mood_positive_s:mood_negative_s | ||||||||||||||||||||||||||||||
| ρ01 | 0.49 castor_record_id.mood_negative_s | -0.70 castor_record_id.mood_positive_s | -0.35 castor_record_id.mood_positive_s | -0.91 castor_record_id.mood_positive_s | -0.90 castor_record_id.mood_positive_s | -0.82 castor_record_id.mood_positive_s | -0.96 castor_record_id.mood_positive_s | ||||||||||||||||||||||||||||
| -0.83 castor_record_id.mood_positive_s:mood_negative_s | -0.40 castor_record_id.mood_negative_s | 0.50 castor_record_id.mood_negative_s | -0.79 castor_record_id.mood_negative_s | -0.75 castor_record_id.mood_negative_s | -0.59 castor_record_id.mood_negative_s | -0.85 castor_record_id.mood_negative_s | |||||||||||||||||||||||||||||
| -0.03 castor_record_id.mood_positive_s:mood_negative_s | -0.61 castor_record_id.mood_positive_s:mood_negative_s | 0.45 castor_record_id.mood_positive_s:mood_negative_s | 0.50 castor_record_id.mood_positive_s:mood_negative_s | 0.28 castor_record_id.mood_positive_s:mood_negative_s | 0.56 castor_record_id.mood_positive_s:mood_negative_s | ||||||||||||||||||||||||||||||
| ICC | 0.05 | 0.32 | 0.41 | 0.13 | 0.17 | 0.18 | 0.07 | ||||||||||||||||||||||||||||
| N | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | 82 castor_record_id | ||||||||||||||||||||||||||||
| Observations | 4871 | 4871 | 4871 | 4871 | 4711 | 4711 | 4711 | ||||||||||||||||||||||||||||
| Marginal R2 / Conditional R2 | 0.104 / 0.152 | 0.678 / 0.780 | 0.500 / 0.706 | 0.173 / 0.281 | 0.448 / 0.540 | 0.216 / 0.354 | 0.387 / 0.427 | ||||||||||||||||||||||||||||
# Subset variables of interests
plot.physio <- plot_models(glmer.sc_ton_mood, glmer.sc_phnum_mood, glmer.hr_mean_mood)
rm_term <- as.vector(plot.physio$data$term[1:97])
rm_term <- rm_term[rm_term != "mood_positive_s" & rm_term!="mood_negative_s"]
# Set the colours
col_list <-c('#7570B3','#7570B3','#7570B3',"#D95F02", "#D95F02", '#D95F02', '#D95F02', "#1B9E77", "#1B9E77")
# Make the plot
plot.pos_mood_resid <- plot_models( glmer.sc_ton_mood, glmer.sc_phnum_mood, glmer.sc_ph_mag_mood, glmer.sc_ph_auc_mood,
glmer.hr_mean_mood, glmer.hr_min_mood, glmer.hr_max_mood,
m.labels=c("SC Tonic", "SC Number", "SC Magnitued", "SC AUC","HR Mean", "HR Minimum", "HR Maximum"),
axis.labels = c(" "),
# Stastistical Stuff
transform=NULL,
rm.terms = rm_term,
#show.values = T,
#value.size = 4,
#std.est=T,
show.p=T,
p.shape=T,
p.adjust = "fdr",
legend.pval.title = "Significance",
# Visual Stuff
colors=col_list,
dot.size=2,
line.size = 1,
spacing=0.7,
vline.color = "darkgrey",
legend.title = "") +
ptheme + scale_y_continuous(breaks=c( -0.2, -.1,0, .1,.2)) +
theme(axis.ticks.y=element_blank(),
axis.title = element_text(size=16),axis.text.x=element_text(size=11),
panel.grid.major.x = element_line(colour = "grey95"),
panel.grid.minor.x = element_line(colour = "grey90"))
Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
# Plot and Save
plot.pos_mood_resid + coord_flip(ylim=c(-.25,.25)) + theme(panel.grid.major.y = element_line(colour = "grey95"), panel.grid.minor.y = element_line(colour = "grey90"))
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
#ggsave("figures/fig_MoodkResid_ALL.tiff", units="in", width=5, height=5, dpi=300, compression = 'lzw', bg="transparent")
In the stress week, we see a decreease in both positive mood and physiology. However, we also see an increase in stress, which we know is related to some physiology (specifically, SC magnitude). So we need to actually confirm that what we see in the stress week (i.e. the physiology arousal decrease) is actually due to the positive mood changes. To this end, we perfrom a mediation analysis. We first need to filter out the nan’s here for some reason though, and we cant really add any covariates in an easy way. So we will stick to the simplest model here.
library(mediation)
set.seed(123)
EMA_Sub <- EMA_Data %>% dplyr::select(castor_record_id, Week_Type, sc_phasic_mag_s, mood_positive_s, event_tot_s) %>% filter(complete.cases(.))
Now that we have filtered the data, we run the first of the mediation analyses. Here we test whether the effect of week on the SC measures is mediated by positive mood.
# Set up
# Main effect
fit.totaleffect=glmer(sc_phasic_mag_s ~ Week_Type + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.totaleffect)
Linear mixed model fit by REML ['lmerMod']
Formula: sc_phasic_mag_s ~ Week_Type + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 14521.3
Scaled residuals:
Min 1Q Median 3Q Max
-2.6166 -0.6538 -0.1600 0.3745 6.0787
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.2098 0.458
Residual 1.1053 1.051
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 2.37842 0.05518 43.105
Week_TypeStress -0.17865 0.03046 -5.865
Correlation of Fixed Effects:
(Intr)
Wk_TypStrss -0.279
# Mediations
fit.mediator=glmer(mood_positive_s ~ Week_Type + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.mediator)
Linear mixed model fit by REML ['lmerMod']
Formula: mood_positive_s ~ Week_Type + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 16551.7
Scaled residuals:
Min 1Q Median 3Q Max
-4.6490 -0.6025 0.0561 0.6408 3.7924
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.9616 0.9806
Residual 1.6479 1.2837
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.67833 0.11161 59.83
Week_TypeStress -0.51174 0.03723 -13.75
Correlation of Fixed Effects:
(Intr)
Wk_TypStrss -0.168
# Combined
fit.dv=glmer(sc_phasic_mag_s ~ Week_Type + mood_positive_s + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.dv)
Linear mixed model fit by REML ['lmerMod']
Formula: sc_phasic_mag_s ~ Week_Type + mood_positive_s + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 14522.5
Scaled residuals:
Min 1Q Median 3Q Max
-2.6395 -0.6415 -0.1645 0.3849 6.0210
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.2094 0.4576
Residual 1.1042 1.0508
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 2.19159 0.09483 23.111
Week_TypeStress -0.16440 0.03101 -5.302
mood_positive_s 0.02797 0.01155 2.421
Correlation of Fixed Effects:
(Intr) Wk_TyS
Wk_TypStrss -0.314
mood_pstv_s -0.814 0.190
# Mediation analysis
results = mediate(model.m=fit.mediator, model.y=fit.dv, treat='Week_Type', mediator='mood_positive_s', boot=F, sims=5000)
treatment and control values do not match factor levels; using Control and Stress as control and treatment, respectively
summary(results)
Causal Mediation Analysis
Quasi-Bayesian Confidence Intervals
Mediator Groups: castor_record_id
Outcome Groups: castor_record_id
Output Based on Overall Averages Across Groups
Estimate 95% CI Lower 95% CI Upper p-value
ACME (control) -0.0144 -0.0263 0.00 0.012 *
ACME (treated) -0.0144 -0.0263 0.00 0.012 *
ADE (control) -0.1642 -0.2234 -0.10 <2e-16 ***
ADE (treated) -0.1642 -0.2234 -0.10 <2e-16 ***
Total Effect -0.1786 -0.2367 -0.12 <2e-16 ***
Prop. Mediated (control) 0.0796 0.0169 0.17 0.012 *
Prop. Mediated (treated) 0.0796 0.0169 0.17 0.012 *
ACME (average) -0.0144 -0.0263 0.00 0.012 *
ADE (average) -0.1642 -0.2234 -0.10 <2e-16 ***
Prop. Mediated (average) 0.0796 0.0169 0.17 0.012 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sample Size Used: 4871
Simulations: 5000
The results show that indeed, the results are mediated by positive mood.
We now need to refit the models and check whether event stress is doing any supression or mediation. So we run another model to check that.
# Main effect
fit.totaleffect=glmer(sc_phasic_mag_s ~ Week_Type + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.totaleffect)
Linear mixed model fit by REML ['lmerMod']
Formula: sc_phasic_mag_s ~ Week_Type + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 14521.3
Scaled residuals:
Min 1Q Median 3Q Max
-2.6166 -0.6538 -0.1600 0.3745 6.0787
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.2098 0.458
Residual 1.1053 1.051
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 2.37842 0.05518 43.105
Week_TypeStress -0.17865 0.03046 -5.865
Correlation of Fixed Effects:
(Intr)
Wk_TypStrss -0.279
# Mediations
fit.mediator=glmer(event_tot_s ~ Week_Type + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.mediator)
Linear mixed model fit by REML ['lmerMod']
Formula: event_tot_s ~ Week_Type + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 15902.1
Scaled residuals:
Min 1Q Median 3Q Max
-3.9369 -0.6062 0.0213 0.6250 4.1070
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.1397 0.3738
Residual 1.4829 1.2177
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 5.47163 0.04848 112.866
Week_TypeStress 0.32736 0.03524 9.289
Correlation of Fixed Effects:
(Intr)
Wk_TypStrss -0.368
# Combined
fit.dv=glmer(sc_phasic_mag_s ~ Week_Type + event_tot_s + (1|castor_record_id), EMA_Sub)
calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly
summary(fit.dv)
Linear mixed model fit by REML ['lmerMod']
Formula: sc_phasic_mag_s ~ Week_Type + event_tot_s + (1 | castor_record_id)
Data: EMA_Sub
REML criterion at convergence: 14527.9
Scaled residuals:
Min 1Q Median 3Q Max
-2.6252 -0.6550 -0.1594 0.3737 6.0909
Random effects:
Groups Name Variance Std.Dev.
castor_record_id (Intercept) 0.2097 0.4579
Residual 1.1055 1.0514
Number of obs: 4871, groups: castor_record_id, 82
Fixed effects:
Estimate Std. Error t value
(Intercept) 2.340709 0.087530 26.742
Week_TypeStress -0.180920 0.030734 -5.887
event_tot_s 0.006892 0.012422 0.555
Correlation of Fixed Effects:
(Intr) Wk_TyS
Wk_TypStrss -0.071
event_tot_s -0.776 -0.133
# Mediation analysis
results2 = mediate(model.m=fit.mediator, model.y=fit.dv, treat='Week_Type', mediator='event_tot_s', boot=F, sims=5000)
treatment and control values do not match factor levels; using Control and Stress as control and treatment, respectively
summary(results2)
Causal Mediation Analysis
Quasi-Bayesian Confidence Intervals
Mediator Groups: castor_record_id
Outcome Groups: castor_record_id
Output Based on Overall Averages Across Groups
Estimate 95% CI Lower 95% CI Upper p-value
ACME (control) 0.00228 -0.00563 0.01 0.58
ACME (treated) 0.00228 -0.00563 0.01 0.58
ADE (control) -0.18031 -0.23996 -0.12 <2e-16 ***
ADE (treated) -0.18031 -0.23996 -0.12 <2e-16 ***
Total Effect -0.17803 -0.23750 -0.12 <2e-16 ***
Prop. Mediated (control) -0.01238 -0.06363 0.03 0.58
Prop. Mediated (treated) -0.01238 -0.06363 0.03 0.58
ACME (average) 0.00228 -0.00563 0.01 0.58
ADE (average) -0.18031 -0.23996 -0.12 <2e-16 ***
Prop. Mediated (average) -0.01238 -0.06363 0.03 0.58
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sample Size Used: 4871
Simulations: 5000
Here, we see that indeed there is no mediation
We were able to establish that physiology and mood both change in the weeks under chronic stress. That is good, because now we can see how well we can use this informaiton in predictive models. To this end, we use the randomForest package plus some extra functions to test our prediction. Firrst lets set a seed and load a packacge for these analyses.
library(randomForest)
set.seed(123)
Before going into the details of the models, we first subset the data to omit any nans. We then check the out of back error for random forest models predicting week from the data types. We run three models predicting week type from each of the following:
After checking the OOB errors, we can split the data into the training/testing sets.
# Variables for Forest
vars.forest <- c( "Week_Type", "mood_positive", "mood_negative", "sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "acc_delta", "temp_mean")
vars.forest.physio <-c( "sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "Week_Type" )
# Subset the data
df.RandomForest <- EMA_Data[,vars.forest]
df.RandomForest <- na.omit(df.RandomForest)
df.RandomForest.physio <- df.RandomForest[,vars.forest.physio]
This modle classifies week type from the affect items
# Run random forest model for mood vars
forest.mood <- randomForest(Week_Type ~ mood_positive + mood_negative,
data=df.RandomForest,
ntree=5000,
importance = TRUE)
forest.mood
Call:
randomForest(formula = Week_Type ~ mood_positive + mood_negative, data = df.RandomForest, ntree = 5000, importance = TRUE)
Type of random forest: classification
Number of trees: 5000
No. of variables tried at each split: 1
OOB estimate of error rate: 43.45%
Confusion matrix:
Control Stress class.error
Control 1397 824 0.3710041
Stress 1128 1144 0.4964789
Now we can check what the physio data looks like. The OOB is 38.43 for the mood data. Can we do better with the full data? And what is the most important variable in these models?
# Run random forest full model
vars.forest.physio <- c( "sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "acc_delta", "temp_mean")
forest.full <- randomForest( as.formula(paste("Week_Type", "~", (paste(vars.forest.physio, collapse="+")))) ,
data=df.RandomForest,
ntree=5000,
importance = TRUE)
forest.full
Call:
randomForest(formula = as.formula(paste("Week_Type", "~", (paste(vars.forest.physio, collapse = "+")))), data = df.RandomForest, ntree = 5000, importance = TRUE)
Type of random forest: classification
Number of trees: 5000
No. of variables tried at each split: 3
OOB estimate of error rate: 45.36%
Confusion matrix:
Control Stress class.error
Control 1156 1065 0.4795137
Stress 973 1299 0.4282570
randomForest::importance(forest.full)
Control Stress MeanDecreaseAccuracy MeanDecreaseGini
sc_tonic_mean -8.9853097 21.631419 12.072315 237.7048
sc_phasic_mag -11.1918958 20.421922 9.939339 174.0730
sc_phasic_dur 22.8649025 -9.571561 19.010894 104.3321
sc_phasic_auc 0.7914564 13.632900 20.724970 229.0421
sc_phasic_num 10.8494712 4.837696 22.724805 124.5621
hr_mean 2.0238012 8.829096 12.024067 224.0586
hr_max -2.3256789 16.142368 15.600133 225.0406
hr_min -15.8804828 30.525435 14.546899 222.8330
hr_sd -3.6938560 12.473994 8.642465 220.1086
acc_delta 21.6679819 -6.470493 13.461728 239.2759
temp_mean -1.1658008 18.136056 12.441982 242.1378
Next up I will select the all variables and see if it improves our model.
# Run the forest with most important features
forest.important <- randomForest(Week_Type ~ .,
data=df.RandomForest,
ntree=5000,
importance = TRUE)
forest.important
Call:
randomForest(formula = Week_Type ~ ., data = df.RandomForest, ntree = 5000, importance = TRUE)
Type of random forest: classification
Number of trees: 5000
No. of variables tried at each split: 3
OOB estimate of error rate: 41.09%
Confusion matrix:
Control Stress class.error
Control 1250 971 0.4371905
Stress 875 1397 0.3851232
Ok so first I looked at the random forest models as a whole without really doing any type of validation of the predictions. We can see that if we look at the mood, we get better predictions for stress and control weeks than looking at the whole set of physio parameters. Thats interesting, but unsurprising. We now need to do some testing and validation.
In order to the validation, we try out a leave-one-beep-out (LOBO) analysis. This analysis will run a random forest model for each subject separately, leaving out one survey when running the model. We then test the model on the beep that was left out. We repeat this process for the subject until we’ve removed each survey/beep out once. This results in a series of predictions that give us an error level for each subject. In order to do this, we have developed a function that is provided in this github directory.
We first run the LOBO model using the custom function.
# Then with the full model
vars.forest.mood <- c("mood_positive_c", "mood_negative_c")
forest.lobo.mood <- rf.lobo(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.mood,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% Complete
as.data.frame(forest.lobo.mood$total$subject_errors)
psych::describe(forest.lobo.mood$total$subject_errors)
We see we get an estimated error of around 33% for this model. Thats cool. Now we need to test it against the random error. One can assume in theory that the prediction error for a dichotomous variable is 50/50, but we dont like to do things the easy way. Instead, we will do 10000 iterations where we bootstrap resample the stress and control weeks. This will give us the real error rate with a sampling distribution. This was made into a function, but for some reason I couldnt get the function to run in parallel. So instead I run the parallel processing of the bootstrap outside of a function. Its not pretty, but it works.
# BootstrapLOBO.
# { cl <- makeCluster(NoCores-1)
# registerDoSNOW(cl)
# iterations <- 10000
# print("Running, this will take a while...", quote=F)
# pb <- txtProgressBar(max = iterations, style = 3)
# progress <- function(n) setTxtProgressBar(pb, n)
# opts <- list(progress = progress)
# forest.boot.mood <- foreach(i=1:iterations, .options.snow = opts ) %dopar% {
# rf.BootstrapError(Data=EMA_Data,
# Shuffle="Week_Type",
# Iterations=1,
# SubjectId="castor_record_id",
# xvar=vars.forest.mood,
# yvar="Week_Type",
# Trees=500)
# }
# print("Done!", quote=F)
# stopCluster(cl)
# # Now merge them into one dataframe
# pb <- txtProgressBar(max =length(forest.boot.mood), style = 3)
# forest.boot.mood.merge <- as.data.frame(forest.boot.mood[[1]][2])
# for (i in 2:length(forest.boot.mood)) {
# setTxtProgressBar(pb, i)
# df.2merge <- as.data.frame(forest.boot.mood[[i]][2])
# forest.boot.mood.merge <- merge (df.2merge, forest.boot.mood.merge , by="DataFrame.id")
# }
# # After merging the results into a single data frame, lets also everage the error rate
# forest.boot.mood.merge$averageError <- rowMeans(forest.boot.mood.merge [, -which(names( forest.boot.mood.merge) %in% c("DataFrame.id"))], na.rm=T)
# saveRDS(forest.boot.mood.merge, file = "data/bootstrap_mood.rds")
# }
Now that we have run the bootstrap, we also save it just in case, and then we get the average error, and calcualte the true SD and SE from the sampling distribution.
# Print the Errors
boot.mood.descr <- psych::describe(forest.boot.mood.merge$averageError)
# Also get the true SD of bootstraps
boot.mood.descr$sd <- mean((psych::describe(forest.boot.mood.merge))$sd, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.mood.descr$se <- mean((psych::describe(forest.boot.mood.merge))$se, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.mood.descr
I will now test the LOBO model using Mood against the bootstrapped LOBO model with the same variables. I made a function to do this. The finction will first calculate a z-score for each subject based on the distribution of the bootstrapped models, then it will calculate the P-value from the z-score. Finally the function sums the z-scores using the stouffer method. Using this method, we see the LOBO models perfrom significantly better than chance. Yay! So within-subject approach works super well!
lobo.mood_null <- rf.null_test(forest.lobo.mood, forest.boot.mood.merge, model_type="LOBO", method="actual")
Loading required package: poolr
lobo.mood_null
$p_val
[1] 0.1597 0.0197 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[23] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[45] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[67] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 NA
$combined
combined p-values with: Stouffer's method
number of p-values combined: 82
test statistic: 33.193 ~ N(0,1)
adjustment: none
combined p-value: <2e-16
The second model I will test is whether we can predict week type from the physiology data alone. For this, I run the model first to get the LOBO error rate.
We see that it does a bit worse than model 1. But we still need to check the bootstrap error for the model with the physio data. It should be similar to that of the mood though.
# Then with the full model
vars.forest.physio <- c("sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "acc_delta", "temp_mean")
forest.lobo.physio <- rf.lobo(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.physio,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
The `i` argument of ``[.tbl_df`()` must lie in [0, rows] if positive, as of tibble 3.0.0.
Use `NA` as row index to obtain a row full of `NA` values.
[90mThis warning is displayed once every 8 hours.[39m
[90mCall `lifecycle::last_warnings()` to see where this warning was generated.[39mThe `i` argument of ``[.tbl_df`()` must lie in [-rows, 0] if negative, as of tibble 3.0.0.
Use `NA` as row index to obtain a row full of `NA` values.
[90mThis warning is displayed once every 8 hours.[39m
[90mCall `lifecycle::last_warnings()` to see where this warning was generated.[39m
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% Complete
as.data.frame(forest.lobo.physio$total$subject_errors)
psych::describe(forest.lobo.physio$total$subject_errors)
We again do the bootstrap model, and then save it as an object for later use.
# # LOBO Bootstrapping
# { cl <- makeCluster(NoCores-1)
# registerDoSNOW(cl)
# iterations <- 10000
# print("Running, this will take a while...", quote=F)
# pb <- txtProgressBar(max = iterations, style = 3)
# progress <- function(n) setTxtProgressBar(pb, n)
# opts <- list(progress = progress)
# forest.boot.physio <- foreach(i=1:iterations, .options.snow = opts ) %dopar% {
# rf.BootstrapError(Data=EMA_Data,
# Shuffle="Week_Type",
# Iterations=1,
# SubjectId="castor_record_id",
# xvar=vars.forest.physio,
# yvar="Week_Type",
# Trees=500)
# }
# print("Done!", quote=F)
# stopCluster(cl)
#
# # Now merge them into one dataframe
# pb <- txtProgressBar(max =length(forest.boot.physio), style = 3)
# forest.boot.physio.merge <- as.data.frame(forest.boot.physio[[1]][2])
# for (i in 2:length(forest.boot.physio)) {
# setTxtProgressBar(pb, i)
# df.2merge <- as.data.frame(forest.boot.physio[[i]][2])
# forest.boot.physio.merge <- merge(df.2merge, forest.boot.physio.merge , by="DataFrame.id",
# suffixes=c((paste(i,".x")),(paste(i,".y"))))
# }
# # Merge it to mean
# forest.boot.physio.merge$averageError <- rowMeans(forest.boot.physio.merge [, -which(names( forest.boot.physio.merge) %in% c("DataFrame.id"))], na.rm=T)
# saveRDS( forest.boot.physio.merge, file = "data/bootstrap_physio.rds")
# }
We now calculate the bootstrap SE and SD
# Print the Errors
boot.physio.descr <- psych::describe(forest.boot.physio.merge$averageError)
# Also get the true SD of bootstraps
boot.physio.descr$sd <- mean((psych::describe(forest.boot.physio.merge))$sd, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.physio.descr$se <- mean((psych::describe(forest.boot.physio.merge))$se, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.physio.descr
So now that I have the averaged bootstrap error for the physio model, lets check if the LOBO is more than random with a test against the bootstrap estimates.
lobo.physio_null <- rf.null_test(forest.lobo.physio, forest.boot.physio.merge, model_type="LOBO", method="actual")
lobo.physio_null
$p_val
[1] 0.5632 0.0333 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[23] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[45] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[67] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
$combined
combined p-values with: Stouffer's method
number of p-values combined: 80
test statistic: 32.62 ~ N(0,1)
adjustment: none
combined p-value: <2e-16
According to the t-test against the bootstrap error sample, the test is above chance level here too. I will again do a model comparison at the end of the model-testing sections.
Finally we check the full model using both physio and mood variables.
# Then with the full model
vars.forest.x <- c("mood_positive_c", "mood_negative_c", "sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "temp_mean")
forest.lobo.full <- rf.lobo(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.x,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% Complete
as.data.frame(forest.lobo.full$total$subject_errors)
psych::describe(forest.lobo.full$total$subject_errors)
Then I can check the bootstrap error for the model combined model as done before:
# {cl <- makeCluster(NoCores-1)
# registerDoSNOW(cl)
# iterations <- 10000
# print("Running, this will take a while...", quote=F)
# pb <- txtProgressBar(max = iterations, style = 3)
# progress <- function(n) setTxtProgressBar(pb, n)
# opts <- list(progress = progress)
# forest.boot.combi <- foreach(i=1:iterations, .options.snow = opts ) %dopar% {
# rf.BootstrapError(Data=EMA_Data,
# Shuffle="Week_Type",
# Iterations=1,
# SubjectId="castor_record_id",
# xvar=vars.forest.x,
# yvar="Week_Type",
# Trees=500)
# }
# print("Done!", quote=F)
# stopCluster(cl)
#
# # Now merge them into one dataframe
# pb <- txtProgressBar(max =length(forest.boot.combi), style = 3)
# forest.boot.combi.merge <- as.data.frame(forest.boot.physio[[1]][2])
# for (i in 2:length(forest.boot.combi)) {
# setTxtProgressBar(pb, i)
# df.2merge <- as.data.frame(forest.boot.combi[[i]][2])
# forest.boot.combi.merge <- merge(df.2merge, forest.boot.combi.merge , by="DataFrame.id",
# suffixes=c((paste(i,".x")),(paste(i,".y"))))
# }
# # Merge it to mean
# forest.boot.combi.merge$averageError <- rowMeans(forest.boot.combi.merge [, -which(names( forest.boot.combi.merge) %in% c("DataFrame.id"))], na.rm=T)
# saveRDS( forest.boot.combi.merge, file = "data/bootstrap_combi.rds")
# }
We then again calculate the SE and SD of the models
# Print the Errors
boot.combi.descr <- psych::describe(forest.boot.combi.merge$averageError)
# Also get the true SD of bootstraps
boot.combi.descr$sd <- mean((psych::describe(forest.boot.combi.merge))$sd, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.combi.descr$se <- mean((psych::describe(forest.boot.combi.merge))$se, na.rm=T)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
boot.combi.descr
And finally I can test the difference between the full model and the bootstrapped one. So we can see again, that our model only improves slightly with the addition of the physio variables (1%). That doesnt seem great. But we can also guess that within the control week there may be times when people are stressed, and vice versa for the stress week.We will do the null test again.
lobo.combi_null <- rf.null_test(forest.lobo.full, forest.boot.combi.merge, model_type="LOBO", method="actual")
lobo.combi_null
$p_val
[1] 0.1731 0.0037 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[23] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[45] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
[67] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
$combined
combined p-values with: Stouffer's method
number of p-values combined: 80
test statistic: 32.837 ~ N(0,1)
adjustment: none
combined p-value: <2e-16
Now that we’ve established all our models do better than the bootstrap version, we can also test the models against each other. We first check the lowest performers.
We filter the data and have to do a couple of manipulations to do a paired t-test.We see that the mood does significantly better
rf.result.df1 <- as.data.frame(forest.lobo.physio$total$subject_errors)
colnames(rf.result.df1)[1] <- "physio"
rf.result.df1$id <- rownames(rf.result.df1)
rf.result.df2 <- as.data.frame(forest.lobo.mood$total$subject_errors)
colnames(rf.result.df2)[1] <- "mood"
rf.result.df2$id <- rownames(rf.result.df2)
rf.result.merge <- merge(rf.result.df1, rf.result.df2, by="id")
tidy(t.test(x=rf.result.merge$physio, y=rf.result.merge$mood, paired=T))
Now I test the mood vs full model. It appears that the full model does a lot better than the one with mood only. So it is safe to say that Model 3 > Model 1 > Model 2
rf.result.df1 <- as.data.frame(forest.lobo.full$total$subject_errors)
colnames(rf.result.df1)[1] <- "full"
rf.result.df1$id <- rownames(rf.result.df1)
rf.result.df2 <- as.data.frame(forest.lobo.mood$total$subject_errors)
colnames(rf.result.df2)[1] <- "mood"
rf.result.df2$id <- rownames(rf.result.df2)
rf.result.merge <- merge(rf.result.df1, rf.result.df2, by="id")
tidy(t.test(x=rf.result.merge$full, y=rf.result.merge$mood, paired=T))
Next up is the standard LOSO. The idea here is that we want to check if we can actually use the data of different participants to predict for a completetly new one. This will remove the enitre EMA data set of a single subject, run the model, then cross validate it with the subject that was left out. I can now run the function below, first with a vector only including the mood items, then the full model:
Our first model looks at the mood ratings predicting which week participants are in. I estimate the LOSO error rates below. The model here doesnt do as well as the model with the lobo. Lets try to use the LOBO null distribution to see if its above chance levels next.
# First with mood items
vars.forest.mood <- c("mood_positive", "mood_negative")
forest.loso.mood <- rf.loso(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.mood,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% complete
as.data.frame(forest.loso.mood$error_rate)
psych::describe(forest.loso.mood$error_rate*100, na.rm=T)
Here I will try to check the LOSO model vs. the null distribution estimated from the bootstrap we did earler. The loso model did not perform better than the bootstrapped estimates.
forest.loso_mood_null <- rf.null_test(forest.loso.mood, forest.boot.mood.merge, model_type="LOSO", method="actual")
forest.loso_mood_null
$p_val
[1] 0.3563 0.5799 0.0000 0.7926 0.0000 0.0000 0.0000 0.0000 0.3076 0.8950 0.0012 0.0076 0.8176 0.5599 1.0000 0.0000 0.0177 0.0225 0.0833 0.0000 1.0000 0.0000
[23] 1.0000 0.0000 0.8348 0.7252 1.0000 0.0000 0.9897 0.0000 0.0004 0.0000 0.0000 0.1273 0.0001 0.9952 0.9466 0.0113 0.0000 0.9514 0.2565 0.0000 0.0000 0.0000
[45] 0.9906 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 1.0000 0.0022 0.0000 0.6286 0.9995 0.0000 1.0000 0.9948 0.0000 0.0020 1.0000 0.0001 1.0000
[67] 0.0016 0.2036 0.0000 0.0000 1.0000 0.9998 0.6477 1.0000 1.0000 0.0015 1.0000 0.0643 0.0000 0.0282 0.0006 0.0000 1.0000
$combined
combined p-values with: Stouffer's method
number of p-values combined: 83
test statistic: -Inf ~ N(0,1)
adjustment: none
combined p-value: 1
The second model is looking at the physio variables predicting week type. We see that it only achieves 47.83% success. We will test this now against the bootstrapped error rate. #### Model{-}
# Then with the full model
vars.forest.physio <- c("sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "acc_delta", "temp_mean")
forest.loso.physio <- rf.loso(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.physio,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% complete
as.data.frame(forest.loso.physio$error_rate)
psych::describe(forest.loso.physio$error_rate*100)
Next we check the physio variables against the null distribution. Here we see that it its also not signficantly better than chance.
forest.loso_physio_null <- rf.null_test(forest.loso.physio, forest.boot.physio.merge, model_type="LOSO", method="actual")
forest.loso_physio_null
$p_val
[1] 0.4703 0.8593 0.2199 0.4417 0.8771 0.0782 0.9687 0.4285 0.0932 NA 0.0021 0.1961 0.0539 0.7650 0.2076 0.0000 0.0000 1.0000 0.0000 0.9629 1.0000 0.0000
[23] 0.0000 0.0305 0.0000 0.2412 1.0000 0.3724 0.9777 0.0000 0.0090 1.0000 0.5665 0.0000 0.0073 0.9108 0.5631 0.9988 0.9466 0.0000 0.0006 0.1017 0.0000 0.9665
[45] 0.5722 0.3070 0.0000 1.0000 0.0000 0.0000 1.0000 0.0001 1.0000 0.9998 0.0000 0.1559 0.1032 1.0000 0.0233 1.0000 1.0000 0.0017 0.9999 0.5887 1.0000 1.0000
[67] 0.0244 0.0000 0.0000 0.9664 0.0005 0.0000 0.0166 1.0000 0.0106 1.0000 0.0000 0.9998 1.0000 0.9994
$combined
combined p-values with: Stouffer's method
number of p-values combined: 79
test statistic: -Inf ~ N(0,1)
adjustment: none
combined p-value: 1
FInally, the third model looks at everything (i.e. both physio and mood). This has an error rate of 43% which still sucks. Lets test this next against the bootstrap error #### Model {-}
# Then with the full model
vars.forest.x <- c("mood_positive_c", "mood_negative_c", "sc_tonic_mean", "sc_phasic_mag", "sc_phasic_dur", "sc_phasic_auc", "sc_phasic_num","hr_mean", "hr_max", "hr_min", "hr_sd", "acc_delta", "temp_mean")
forest.loso.full <- rf.loso(Data=EMA_Data,
SubNr="castor_record_id",
xvars=vars.forest.x,
yvar="Week_Type",
NoTree=5000)
[1] 0% complete
[1] 10% complete
[1] 20% complete
[1] 30% complete
[1] 40% complete
[1] 50% complete
[1] 60% complete
[1] 70% complete
[1] 80% complete
[1] 90% complete
[1] 100% complete
as.data.frame(forest.loso.full$error_rate)
psych::describe(forest.loso.full$error_rate*100)
Finally we test the model with both against the null distribution.This one is also not significantly better than chance.
forest.loso_full_null <- rf.null_test(forest.loso.full, forest.boot.combi.merge, model_type="LOSO", method="actual")
forest.loso_full_null
$p_val
[1] 0.0496 0.2528 0.0000 0.0485 0.0641 0.7740 0.0409 0.0000 0.0001 NA 0.0545 0.6610 0.6780 0.0003 1.0000 0.0000 0.0000 0.5450 0.5457 0.9957 0.0000 0.0000
[23] 0.0000 0.0000 0.0000 0.5653 0.8627 0.3768 0.0000 0.0000 0.0000 1.0000 0.0000 0.1334 0.0000 0.0000 0.0000 0.2496 0.0000 0.0000 0.0000 0.0000 0.0000 0.0062
[45] 0.0000 0.0000 0.0000 0.8257 0.0000 0.0000 0.3471 0.0000 0.0009 0.9658 0.0000 0.0002 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 0.0002 0.0000 1.0000
[67] 0.0001 0.0001 0.0000 0.0000 0.0000 0.0629 0.0199 0.0000 1.0000 0.0155 0.0081 0.0000 0.6212 0.0078
$combined
combined p-values with: Stouffer's method
number of p-values combined: 79
test statistic: -Inf ~ N(0,1)
adjustment: none
combined p-value: 1
Based on all three tests for the models against the null we can conclude that the LOSO models do not in fact perform better than chance.
Based on the error rate, lets see if one model does a better job than the other:
rf.loso.mood <- as.data.frame(forest.loso.mood$error_rate)
rf.loso.mood$id <- rownames(rf.loso.mood)
rf.loso.physio <- as.data.frame(forest.loso.physio$error_rate)
rf.loso.physio$id <- rownames(rf.loso.physio)
rf.loso.full <- as.data.frame(forest.loso.full$error_rate)
rf.loso.full$id <- rownames(rf.loso.full)
rf.result.merge <- merge(rf.loso.mood, rf.loso.physio, by="id")
rf.result.merge <- merge(rf.result.merge, rf.loso.full, by="id")
tidy(t.test(x=rf.result.merge$`forest.loso.mood$error_rate`, y=rf.result.merge$`forest.loso.physio$error_rate`, paired=T))
tidy(t.test(x=rf.result.merge$`forest.loso.mood$error_rate`, y=rf.result.merge$`forest.loso.full$error_rate`, paired=T))
tidy(t.test(x=rf.result.merge$`forest.loso.physio$error_rate`, y=rf.result.merge$`forest.loso.full$error_rate`, paired=T))
It looks like there is no significant difference between the error rates in the paired sample t-test in these three models. What could this mean? That regardless of what model we use at a population level, we still are not able to make decent predictions. I think that these models arent good at population level predictions, and this is pretty obnvious if we look at the within-subject variance from our linear models. Most of the variance comes from between subjects. Another approach is warranted.
I next waht to make a plot of my models with the standard error. I first merge them into one dataframe, then I can actually plot them.
# I will rename the bootstrap coloumns so I can add them to the full model dataframe for plotting
df_boot1 <- forest.boot.mood.merge[,c("DataFrame.id" ,"averageError")]
df_boot1 <- df_boot1 %>% dplyr::rename(id=DataFrame.id, error=averageError)
df_boot1 <- tibble::add_column(df_boot1, model="boot.mood", .after="id")
df_boot2 <- forest.boot.physio.merge %>% dplyr::select(DataFrame.id, averageError) %>% dplyr::rename(id=DataFrame.id, error=averageError)
df_boot2 <- tibble::add_column(df_boot2, model="boot.physio", .after="id")
df_boot3 <- forest.boot.combi.merge %>% dplyr::select(DataFrame.id, averageError) %>% dplyr::rename(id=DataFrame.id, error=averageError)
df_boot3 <- tibble::add_column(df_boot3, model="boot.full", .after="id")
# Join the boot straps
df_boot <- full_join(df_boot1, df_boot2)
Joining, by = c("id", "model", "error")
df_boot <- full_join(df_boot, df_boot3)
Joining, by = c("id", "model", "error")
# Make the results and merge boot
df_loo <- gather(rf.combined.errors,model, error, loso.mood:lobo.full, factor_key=TRUE)
df_loo <- full_join(df_loo, df_boot)
Joining, by = c("id", "model", "error")
Column `model` joining factor and character vector, coercing into character vector
# Separate coloumns for plotting
df_loo <- separate(df_loo, model, into=c("Method", "Model"))
df_loo_sum <- data_summary(df_loo, "error", c("Method", "Model"))
# Set the SD and SE of bootstrap models to the correct ones of whole model
df_loo_sum$sd[df_loo_sum$Method=="boot" & df_loo_sum$Model=="mood"] <- boot.mood.descr$sd
df_loo_sum$se[df_loo_sum$Method=="boot" & df_loo_sum$Model=="mood"] <- boot.mood.descr$se
df_loo_sum$sd[df_loo_sum$Method=="boot" & df_loo_sum$Model=="physio"] <- boot.physio.descr$sd
df_loo_sum$se[df_loo_sum$Method=="boot" & df_loo_sum$Model=="physio"] <- boot.physio.descr$se
df_loo_sum$sd[df_loo_sum$Method=="boot" & df_loo_sum$Model=="full"] <- boot.combi.descr$sd
df_loo_sum$se[df_loo_sum$Method=="boot" & df_loo_sum$Model=="full"] <- boot.combi.descr$se
# Set the factor to make it pretty
df_loo_sum$Method <- factor(df_loo_sum$Method, levels =c("lobo", "loso", "boot"), labels = c("LOBO", "LOSO", "Bootstrap"))
df_loo_sum$Model<- factor(df_loo_sum$Model, levels =c("mood", "physio", "full"), labels = c("Model 1:\nMood", "Model 2:\n Physiology", "Model 3:\nCombination"))
figure.loo <- ggplot(df_loo_sum, aes(x=Model, y=error, colour=Method, fill=Method)) +
geom_bar(stat="summary", position = position_dodge2()) +
geom_errorbar(aes(ymin=error-se, ymax=error+se), width=.2, position=position_dodge(.9), colour="black") +
scale_y_continuous(breaks=c(0,10,20,30,40,50, 60, 70, 80), minor_breaks=c(5,15,25,35,45,55,65,75, 85) )+
scale_colour_brewer(palette="Set2") + scale_fill_brewer(palette="Set2") +
xlab("")+ ylab("Error Rate (%)\n") +
theme(text=element_text(size=16, family="Calibri"),
axis.line = element_line(size = 1, colour = "grey"),
panel.background = element_rect(fill="transparent"),
panel.grid.minor.y = element_line(colour="grey95"),
panel.grid.major.y = element_line(colour = "grey95"));
ggsave("figures/fig_RFModels.tiff", units="in", width=6, height=4, dpi=300, compression = 'lzw')
TIFFOpen: figures/fig_RFModels.tiff: No such file or directory.
figure.loo
Now I want to see for each of the models, which one performs best. I first need to split the long dataframe I made for the figures into a wide format.
df_loo_wide <- pivot_wider(df_loo,id_cols = id, names_from=c(Method, Model), values_from=error)
print(df_loo_wide)
tidy(t.test(df_loo_wide$lobo_mood, df_loo_wide$boot_mood , paired = T))
tidy(t.test(df_loo_wide$loso_mood, df_loo_wide$boot_mood , paired = T))
tidy(t.test(df_loo_wide$lobo_mood, df_loo_wide$loso_mood , paired = T))
tidy(t.test(df_loo_wide$lobo_physio, df_loo_wide$boot_physio , paired = T))
tidy(t.test(df_loo_wide$loso_physio, df_loo_wide$boot_physio , paired = T))
tidy(t.test(df_loo_wide$lobo_physio, df_loo_wide$loso_physio , paired = T))
tidy(t.test(df_loo_wide$lobo_full, df_loo_wide$boot_full , paired = T))
tidy(t.test(df_loo_wide$loso_full, df_loo_wide$boot_full , paired = T))
tidy(t.test(df_loo_wide$lobo_full, df_loo_wide$loso_full , paired = T))
Social Stress